I need to modify the value 0 to 1 in column H if on the same row: (I am munipulating csv files, and the macro is in a xlsb file)
1. F is exactly "P1"
2. column O contains keywords "P-" and 'STORM MANHOLE"
this should be very straight forward and it is not working..... help !
sample file and code below
below is the first part where the csv was opened and defined
1. F is exactly "P1"
2. column O contains keywords "P-" and 'STORM MANHOLE"
this should be very straight forward and it is not working..... help !
sample file and code below
VBA Code:
Sub ChangeValue()
Dim i As Long, lastRow As Long
lastRow = ws1.Cells(ws1.Rows.Count, "O").End(xlUp).Row
For i = 2 To lastRow
If Trim(ws1.Range("O" & i).Value) Like "*P-*" And _
Trim(ws1.Range("O" & i).Value) Like "*STORM MANHOLE*" And _
Trim(ws1.Range("F" & i).Value) Like "P1" Then
ws1.Range("H" & i).Value = 1
End If
Next i
End Sub
below is the first part where the csv was opened and defined
VBA Code:
Option Explicit
Option Compare Text
Public wb1 As Workbook, wb2 As Workbook
Public ws1 As Worksheet, ws2 As Worksheet
Sub OpenQuoteFile()
Dim csvFilePath As String, xlsmFilePath As String
csvFilePath = Application.GetOpenFilename("CSV Files (*.csv),*.csv")
If csvFilePath <> "False" Then
Set wb1 = Workbooks.Open(csvFilePath)
Set ws1 = wb1.Sheets(1)
Else
Exit Sub
End If
xlsmFilePath = Application.GetOpenFilename("XLSM Files (*.xlsm),*.xlsm")
If xlsmFilePath <> "False" Then
Set wb2 = Workbooks.Open(xlsmFilePath)
Set ws2 = wb2.Sheets("QUOTE")
Else
wb1.Close SaveChanges:=False
Exit Sub
End If
Dim i As Long
For i = 19 To 46
If ws2.Range("D" & i).Value <> "" Then
ws2.Range("D" & i).Copy
ws1.Range("S1:S28").NumberFormat = "@"
ws1.Range("S1:S28").Value = ws2.Range("D19:D46").Value
If ws2.Range("D" & i).MergeCells Then
ws1.Range("S" & i - 28).UnMerge
End If
ws1.Range("S1:S28").EntireColumn.AutoFit
End If
Next i
For i = 19 To 46
If ws2.Range("E" & i).Value <> "" Then
ws2.Range("E" & i).Copy
ws1.Range("T1:T28").NumberFormat = "@"
ws1.Range("T1:T28").Value = ws2.Range("E19:E46").Value
If ws2.Range("E" & i).MergeCells Then
ws1.Range("T" & i - 28).UnMerge
End If
ws1.Range("T1:T28").EntireColumn.AutoFit
End If
Next i
For i = 19 To 46
If ws2.Range("F" & i).Value <> "" Then
ws2.Range("F" & i).Copy
ws1.Range("U1:U28").NumberFormat = "@"
ws1.Range("U1:U28").Value = ws2.Range("F19:F46").Value
If ws2.Range("F" & i).MergeCells Then
ws1.Range("U" & i - 28).UnMerge
End If
ws1.Range("U1:U28").EntireColumn.AutoFit
End If
Next i
Application.CutCopyMode = False
wb2.Close SaveChanges:=False
Application.ScreenUpdating = True
End Sub