stirlingmw1
Board Regular
- Joined
- Jun 17, 2016
- Messages
- 53
- Office Version
- 2016
- 2013
- 2010
- 2007
- Platform
- Windows
I have this piece of code that adds data to the next available column on worksheet(WSName1)
I am trying to add to it so that it checks to see whether the data is already present. The criteria that it needs to check against are in the first 3 rows of each column. If these criteria are met then rows 5 to lastrow of that column are amended, however If these criteria are not met it then the data is added to the next available column.
I am using the following code which isnt quite working as the data is added to the next available column anyway even if the criteria are met, am I on the right lines??
Thanks
Steve
VBA Code:
With Worksheets(WSName1)
.Cells(1, LastColumn).Value = CmboUnit.Value
.Cells(2, LastColumn).Value = CmboApr.Value
.Cells(3, LastColumn).Value = "April"
.Range(.Cells(5, LastColumn), .Cells(Lastrow, LastColumn)).Value = Worksheets("Requirements").Range("I3:I" & Lastrow).Value
End With
I am trying to add to it so that it checks to see whether the data is already present. The criteria that it needs to check against are in the first 3 rows of each column. If these criteria are met then rows 5 to lastrow of that column are amended, however If these criteria are not met it then the data is added to the next available column.
I am using the following code which isnt quite working as the data is added to the next available column anyway even if the criteria are met, am I on the right lines??
VBA Code:
'Checks to see if the 3 top cells in the worksheet WSName1 contains the same data as in the CmboUnit, CmboApril Comboboxes and the 3rd cell has the work April in it
If Worksheets(WSName1).Cells(1, LastColumn).Value = CmboUnit.Value And _
Worksheets(WSName1).Cells(2, LastColumn).Value = CmboApr.Value And _
Worksheets(WSName1).Cells(3, LastColumn).Value = "April" Then
Worksheets(WSName1).Range(.Cells(Column, Lastrow).Cells(Lastrow, LastColumn)).Value = Worksheets("Requirements").Range("I3:I" & Lastrow).Value
Else
'if false add the data to a new column
With Worksheets(WSName1)
.Cells(1, LastColumn).Value = CmboUnit.Value
.Cells(2, LastColumn).Value = CmboApr.Value
.Cells(3, LastColumn).Value = "April"
.Range(.Cells(5, LastColumn), .Cells(Lastrow, LastColumn)).Value = Worksheets("Requirements").Range("I3:I" & Lastrow).Value
End With
End If
Thanks
Steve