Need to change certain cell values in newly created row

lboone

New Member
Joined
Jan 18, 2022
Messages
2
Office Version
  1. 2010
Platform
  1. Windows
Hello, I found a macro online to insert a new row into the correct alphabetical position in a table. I know I can autofill some individual cells in the new row based on input boxes or other cell values. But I need to input 0's into multiple other cells in the new row. Is there a way to do this without adding lines in my macro for each individual cell?
 

Attachments

  • Screenshot 2022-01-18 160305.jpg
    Screenshot 2022-01-18 160305.jpg
    52.3 KB · Views: 11

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Get the column index of AE (31) and of AK (37) and loop over those cells using For Next loop and in that row and set the cell value to 0?
Actual code is much preferred over pictures.
 
Upvote 0
Hi lboone,

Welcome to MrExcel!!

Try this one liner for all the columns you want to set to zero in the newly inserted row:

VBA Code:
Range("H" & lPosition + 1 & ":I" & lPosition + 1 & ",W" & lPosition + 1 & ",AE" & lPosition + 1 & ":AK" & lPosition + 1).Value = 0

Regards,

Robert
 
Upvote 0
Solution
Hi lboone,

Welcome to MrExcel!!

Try this one liner for all the columns you want to set to zero in the newly inserted row:

VBA Code:
Range("H" & lPosition + 1 & ":I" & lPosition + 1 & ",W" & lPosition + 1 & ",AE" & lPosition + 1 & ":AK" & lPosition + 1).Value = 0

Regards,

Robert
Thank you! That is exactly what I was looking for.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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