Excel VBA質問箱 IV

当質問箱は、有志のボランティア精神のおかげで成り立っています。
問題が解決したら、必ずお礼をしましょうね。
本サイトの基本方針をまとめました。こちら をご一読ください。

投稿種別の選択が必要です。ご注意ください。
迷惑投稿防止のため、URLの入力を制限しています。ご了承ください。


21326 / 76732 ←次へ | 前へ→

【60807】Re:[無題]
発言  新参者2  - 09/3/16(月) 14:42 -

引用なし
パスワード
   ▼横入り さん:
端折っている部分もございますが、だいたい下記の内容が主要です。
ただ不要な部分が多いことや下記内容では伝わらないかもしれませんが、
そのときはご返信ください。

----------------------------------------
ユーザーフォーム  'ユーザーフォーム1の後、下記ユーザーフォームが開く

Sub commandbutton1_click()

Dim folderPath As String

Dim FileNames
 Dim CSVname As String
 Dim tmpSheet As Worksheet '開くCsvファイル
 Dim ActSheet As Worksheet 'コピー先シート
 Dim a As Long, e As Long, g As Long
 Dim b As Long, f As Long
 Dim c As Long
 Dim d As Long
 Dim h As Long, i As Long, j As Long, k As Long
 Dim l As Long, m As Long, n As Long, o As Long
 Dim p As Long, q As Long, r As Long, s As Long
 Dim t As Long, u As Long
 
 
If OptionButton1 = True Then 
 'ユーザーフォームにあるオプションボタン1つの動作

Unload UserForm1

Set sh1 = Sheets("Sheet1")
Set sh2 = Sheets("Sheet2")

 b = sh2.Cells(6, 8).Value
 c = sh2.Cells(5, 21).Value
 d = sh2.Cells(7, 6).Value

   
CreateObject("WScript.Shell").CurrentDirectory = "○○"
  FileNames = Application.GetOpenFilename("CSV File,*.csv", MultiSelect:=True)
  If VarType(FileNames) = vbBoolean Then Exit Sub

   Set ActSheet = ActiveSheet
  Application.ScreenUpdating = False
  e = 1 'コピー列
  For a = 1 To UBound(FileNames)
    CSVname = Mid$(FileNames(a), InStrRev(FileNames(a), "\") + 1)
    ActSheet.Cells(1, e).Value = CSVname
    ActSheet.Cells(2, e).Value = "○○"
    Set tmpSheet = Workbooks.Open(FileNames(a), Local:=True).Sheets(1)
    With tmpSheet
      .Cells(c, 1).Resize(b).Copy ActSheet.Cells(3, e)
      .Parent.Close False
    End With
    Set tmpSheet = Nothing
    e = e + 4
    
    
  Next
  Application.CutCopyMode = False
  Application.ScreenUpdating = False
  
  f = 2
  For g = 1 To UBound(FileNames)
  
  ActSheet.Cells(2, f).Value = "○○"
  Set tmpSheet = Workbooks.Open(FileNames(g), Local:=True).Sheets(1)
    With tmpSheet
      .Cells(c, 2).Resize(b).Copy ActSheet.Cells(3, f)
      .Parent.Close False
    End With
    Set tmpSheet = Nothing
    f = f + 4
        
  Next
  Application.CutCopyMode = False
  Application.ScreenUpdating = False
  
  h = 3
  For i = 1 To UBound(FileNames)
  
  ActSheet.Cells(2, h).Value = "○○"
  Set tmpSheet = Workbooks.Open(FileNames(i), Local:=True).Sheets(1)
    With tmpSheet
      .Cells(c, 3).Resize(b).Copy ActSheet.Cells(3, h)
      .Parent.Close False
    End With
    Set tmpSheet = Nothing
    h = h + 4
        
  Next
  Application.CutCopyMode = False
  Application.ScreenUpdating = False


End If


列数を取得

Date1

End Sub

-------------------------------------------
モジュール1
-----------------------------------------------------
Sub Date1()

Set sh1 = Sheets("sheet1")
Set sh2 = Sheets("sheet2")

Dim u As Long, t As Long
Dim h As Long
Dim w As Integer
Dim x As Integer
Dim o As Long, p As Long
Dim r As Single

t = sh2.Cells(4, 2).Value
h = sh2.Cells(6, 8).Value

u = 2
If u <= t * 4 Then

For w = u To 4 * t

 If sh1.Cells(3, u).Value = "" Then
  
   Exit For

sh1.Select
Cells.Clear
  
 End If

x = sh1.Cells(65536, u).End(xlUp).Row
sh2.Cells(18, 8).Value = x

If sh1.Cells(3, u).Value <> "" Then
sh1.Cells(2, u + 2).Value = "○○"
End If

For o = 3 To x

sh1.Cells(o, u + 2).FormulaR1C1 = "=RC[-1]/1000+RC[-2]"

Selection.NumberFormatLocal = "G/標準"
Selection.NumberFormatLocal = "0.000_ "

Next o


sh1.Select
Cells(3, u + 2).Resize(x).Select
Charts.Add
 ActiveChart.ChartType = xlLineMarkers

    
  ActiveChart.Axes(xlValue).MajorGridlines.Select
  With Selection.Border
    .ColorIndex = 2
    .Weight = xlHairline
    .LineStyle = xlContinuous
  End With

  ActiveChart.Axes(xlCategory).Select
  With Selection.Border
    .Weight = xlHairline
    .LineStyle = xlAutomatic
  End With
  With Selection
    .MajorTickMark = xlInside
    .MinorTickMark = xlNone
    .TickLabelPosition = xlNone
  End With
  ActiveChart.Axes(xlCategory).Select
  With ActiveChart.Axes(xlCategory)
    .CrossesAt = 1
    .TickLabelSpacing = 1
    .TickMarkSpacing = 1
    .AxisBetweenCategories = True
    .ReversePlotOrder = False
  End With
   
  ActiveChart.PlotArea.Select
  ActiveChart.SeriesCollection(1).Name = sh1.Cells(2, u + 2).Value
  
  With Selection.Border
    .Weight = xlHairline
    .LineStyle = xlAutomatic
  End With
  With Selection.Interior
    .ColorIndex = 2    'グラフの領域を白にする
    .PatternColorIndex = 1
    .Pattern = xlSolid
  End With
  
  With ActiveChart
    .HasTitle = True
    .ChartTitle.Characters.Text = sh1.Cells(1, u - 1).Value
  End With


  ActiveChart.SeriesCollection(1).Select
  With Selection
    .MarkerBackgroundColorIndex = xlAutomatic
    .MarkerForegroundColorIndex = xlAutomatic
    .MarkerStyle = xlNone
    .Smooth = False
    .MarkerSize = 5
    .Shadow = False
  End With
  
  ActiveChart.SeriesCollection(1).Select
 
  
  With Selection
    .MarkerBackgroundColorIndex = xlAutomatic
    .MarkerForegroundColorIndex = xlAutomatic
    .MarkerStyle = xlNone
    .Smooth = False
    .MarkerSize = 5
    .Shadow = False
  End With

   
u = u + 4

Next w


Else
MsgBox "値がおかしいです。"

End If


End Sub

---------------------------------------
モジュール2
---------------------------------------
列数

Sub 列数を取得()

Set sh1 = Sheets("sheet1")
Dim 列数 As Integer
Dim t As Long, w As Long

t = 1
For 列数 = t To 256

If sh1.Cells(3, t + 1).Value = "" And sh1.Cells(3, t + 2).Value = "" Then
 w = t + 1
Sheet2.Select
Sheet2.Cells(2, 2).Value = w
Exit For
End If

t = t + 1
Next 列数

End Sub

-------------------------
モジュール3
--------------------------------
Sub 最終行数カウント()

Dim e As Long, num As Integer

Set sh2 = Sheets("sheet2")
Set sh1 = Sheets("sheet1")

If sh1.Range("A2:B5").CurrentRegion.Rows.Count = "" Then

 Exit Sub

Else

e = sh1.Range("A2:B5").CurrentRegion.Rows.Count
sh2.Cells(17, 8).Value = e

num = sh1.Range("F65536").End(xlUp).Row
sh2.Cells(18, 8).Value = num

End If

End Sub

0 hits

【60781】[無題] 新参者 09/3/14(土) 3:47 質問
【60782】Re:[無題] 横入り 09/3/14(土) 7:35 発言
【60807】Re:[無題] 新参者2 09/3/16(月) 14:42 発言
【60808】Re:[無題] kanabun 09/3/16(月) 16:36 発言
【60809】Re:[無題] 新参者3 09/3/16(月) 17:34 発言
【60811】Re:[無題] kanabun 09/3/16(月) 17:49 発言
【60813】Re:[無題] 新参者4 09/3/16(月) 18:04 発言
【60821】Re:[無題] 新参者5 09/3/17(火) 0:48 質問
【60825】Re:[無題] kanabun 09/3/17(火) 9:43 発言
【60829】Re:[無題] 新参者4 09/3/17(火) 13:47 お礼
【60830】Re:[無題] 新参者6 09/3/17(火) 14:08 発言
【60831】Re:全体の流れを確認しましょう kanabun 09/3/17(火) 14:24 発言
【60832】Re:全体の流れを確認しましょう kanabun 09/3/17(火) 15:00 発言
【60843】Re:全体の流れを確認しましょう 新参 09/3/17(火) 17:48 回答
【60844】Re:全体の流れを確認しましょう kanabun 09/3/17(火) 18:17 発言
【60810】Re:[無題] 新参者3 09/3/16(月) 17:39 発言

21326 / 76732 ←次へ | 前へ→
ページ:  ┃  記事番号:
2610219
(SS)C-BOARD v3.8 is Free