S
scottwilsonx
Hi everyone, I would like your expert help with the following:
I have a VBA macro that is based on information in a sheet calle
"import".
The macro looks at the source data in "import" and everytime there is
change of identifier in column A it increments rows in a sheet calle
""new data set" with the identifier plus the contents of column B, C,
& F. The number of increments made is based on the difference betwee
the dates displayed in column B & C.
I also have a listbox called listbox1 which is filled with values fro
BA1:BA301 and these values relate to column F in the "import
worksheet.
The following code isn't working, in that it doesnt pull across an
data based on the selection made in the listbox1.
Sub CreateData()
'Dim x As String
Dim consname As String
Dim myCell As Range
Dim myRange As Range
Dim i As Long
Dim mySht As Worksheet
Dim DataSht As Worksheet
Set DataSht = ActiveSheet
consname = Sheet1.ListBox1.Value
On Error Resume Next
Worksheets("New Data Set").Delete
Set mySht = Worksheets.Add
mySht.Name = "New Data Set"
For Each myCell In DataSht.Range(DataSht.Range("A2"), _
DataSht.Range("A65536").End(xlUp))
If myCell(1, 5).Value = consname Then
For i = CLng(myCell(1, 2).Value) To CLng(myCell(1, 3).Value)
mySht.Range("A65536").End(xlUp)(2).Value = myCell.Value
mySht.Range("B65536").End(xlUp)(2).Value = i
mySht.Range("C65536").End(xlUp)(2).Value = myCell(1, 4).Value
mySht.Range("D65536").End(xlUp)(2).Value = myCell(1, 8).Value
mySht.Range("E65536").End(xlUp)(2).Value = myCell(1, 6).Value
Next i
End If
Next myCell
mySht.Range("B:B").NumberFormat = "dd/mm/yyyy"
End Sub
Any help gratefully received. Thanks
Scott
I have a VBA macro that is based on information in a sheet calle
"import".
The macro looks at the source data in "import" and everytime there is
change of identifier in column A it increments rows in a sheet calle
""new data set" with the identifier plus the contents of column B, C,
& F. The number of increments made is based on the difference betwee
the dates displayed in column B & C.
I also have a listbox called listbox1 which is filled with values fro
BA1:BA301 and these values relate to column F in the "import
worksheet.
The following code isn't working, in that it doesnt pull across an
data based on the selection made in the listbox1.
Sub CreateData()
'Dim x As String
Dim consname As String
Dim myCell As Range
Dim myRange As Range
Dim i As Long
Dim mySht As Worksheet
Dim DataSht As Worksheet
Set DataSht = ActiveSheet
consname = Sheet1.ListBox1.Value
On Error Resume Next
Worksheets("New Data Set").Delete
Set mySht = Worksheets.Add
mySht.Name = "New Data Set"
For Each myCell In DataSht.Range(DataSht.Range("A2"), _
DataSht.Range("A65536").End(xlUp))
If myCell(1, 5).Value = consname Then
For i = CLng(myCell(1, 2).Value) To CLng(myCell(1, 3).Value)
mySht.Range("A65536").End(xlUp)(2).Value = myCell.Value
mySht.Range("B65536").End(xlUp)(2).Value = i
mySht.Range("C65536").End(xlUp)(2).Value = myCell(1, 4).Value
mySht.Range("D65536").End(xlUp)(2).Value = myCell(1, 8).Value
mySht.Range("E65536").End(xlUp)(2).Value = myCell(1, 6).Value
Next i
End If
Next myCell
mySht.Range("B:B").NumberFormat = "dd/mm/yyyy"
End Sub
Any help gratefully received. Thanks
Scott