Human_doing
Board Regular
- Joined
- Feb 16, 2011
- Messages
- 137
Hi all,
Can anyone please correct the below code which gives error: 'Run-time error '91': Object variable or With block variable not set. What the code is supposed to do is ask user to open an Excel file, count how many rows of data there are (which will vary each time) and insert the below formula in to each cell in column H for rows with data.
Thanks
Can anyone please correct the below code which gives error: 'Run-time error '91': Object variable or With block variable not set. What the code is supposed to do is ask user to open an Excel file, count how many rows of data there are (which will vary each time) and insert the below formula in to each cell in column H for rows with data.
Code:
Private Sub CommandButton1_Click()
'Ask user to select Excel file
NewFN = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls), *.xls", Title:="Select the file with raw data for the report")
If NewFN = False Then
' They pressed Cancel
MsgBox "Stopping because you did not select a file"
Exit Sub
Else
Workbooks.Open Filename:=NewFN
End If
'Set range for duplicate count
Dim Sh As Worksheet
Dim LR As Long
With Sh
LR = .Range("A" & .Rows.Count).End(xlUp).Row
.Range("I2:I" & LR).Formula = "COUNTIF(H:H,H2)>1"
End With
End Sub
Thanks
Last edited: