Complete empty cells with a value

nburaq

Board Regular
Joined
Apr 2, 2021
Messages
222
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi Gents,
I have a huge list which includes columns namely group and points. In group column there is always a value but in points column the value might not exists like value C and E in column group. If there is not any value in column points then a value needs to be written as "N/A". I tried to do it myself using IF ISBLANK function then it writes values to every empty cells. Thanks in advance for all your help. I attach mini sheet and screenshot.
sample.png


Book1
I
14
Sheet1
 
How about:
VBA Code:
 Sub Addvalues()
Dim i As Long, Lr As Long, K As String
Lr = Range("B" & Rows.Count).End(xlUp).Row
For i = 2 To Lr
If Range("B" & i).Value = "Labor" Then K = Range("A" & i).Value
ElseIf Range("B" & i).Value = "Services"  OR Range("B" & i).Value = "Material"  Then
Range("A" & i).Value = K
End If
Next i
End Sub
I tried the code and it gave compile error: Else without If
I corrected to this way but still Material doesnt have order number
VBA Code:
Sub Addvalues()
Dim i As Long, Lr As Long, K As String
Lr = Range("B" & Rows.Count).End(xlUp).Row
For i = 2 To Lr
If Range("B" & i).Value = "Labor" Then
K = Range("A" & i).Value
ElseIf Range("B" & i).Value = "Services" Or Range("B" & i).Value = "Material" Then
Range("A" & i).Value = K
End If
Next i
End Sub
 
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Sorry my fault. Forgot Press One Enter:
VBA Code:
Sub Addvalues()
Dim i As Long, Lr As Long, K As String
Lr = Range("B" & Rows.Count).End(xlUp).Row
For i = 2 To Lr
If Range("B" & i).Value = "Labor" Then
K = Range("A" & i).Value
ElseIf Range("B" & i).Value = "Services" Or Range("B" & i).Value = "Material" Then
Range("A" & i).Value = K
End If
Next i
End Sub
 
Upvote 0
Solution
Sorry my fault. Forgot Press One Enter:
VBA Code:
Sub Addvalues()
Dim i As Long, Lr As Long, K As String
Lr = Range("B" & Rows.Count).End(xlUp).Row
For i = 2 To Lr
If Range("B" & i).Value = "Labor" Then
K = Range("A" & i).Value
ElseIf Range("B" & i).Value = "Services" Or Range("B" & i).Value = "Material" Then
Range("A" & i).Value = K
End If
Next i
End Sub
No worries already thankful for all your help! but this code is not working under this condition;
1618583490544.png
 
Upvote 0
I test with this data it working what is problem.
Check this code at immediate window & then Test code:
VBA Code:
Application.EnableEvents = True
 
Upvote 0
I test with this data it working what is problem.
Check this code at immediate window & then Test code:
VBA Code:
Application.EnableEvents = True
Thanks a lot! Everything works perfectly!
 
Upvote 0

Forum statistics

Threads
1,224,759
Messages
6,180,814
Members
452,996
Latest member
nelsonsix66

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top