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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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,223,767
Messages
6,174,399
Members
452,561
Latest member
amir5104

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