Inserting partial column VBA

keef2

Board Regular
Joined
Jun 30, 2022
Messages
185
Office Version
  1. 365
Platform
  1. Windows
Hello,

I currently have this code that works to insert full rows. However, I was hoping to limit the inserting of the row to columns A:J.
Bonus points to see who can help me figure out that if I delete column C why my current code doesn't work?

I tried to add .resize(1,10) but for some reason I keep getting errors, maybe the location in which i try to add this function. Any guidance/help is appreciated as always!

As you can see after I hit the add row button my code output is this:

Schedule KEM WORKING.xlsm
ABDEFGHIJKL
27Job #: Time:7:0025
28 26
29Employees :27
3028
3129
3230
33Job #: Time:7:00
34 
35Employees :
36
37
38
3931
4032
Schedule
Cell Formulas
RangeFormula
E27,E33E27=IFERROR(VLOOKUP(B27,Table2,2,FALSE),"")
E28,E34E28=IFERROR(VLOOKUP(B27,Table2,3,FALSE),"")
L27:L32,L40L27=L26+1
L39L39=L32+1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
C33:H33Expression=COUNTIF($C33,"*Job*")textNO
C27:H27Expression=COUNTIF($C27,"*Job*")textNO



Here is my current code:
VBA Code:
Sub Add_Job()
    
    Dim act As Worksheet
    Set act = ThisWorkbook.ActiveSheet
    bot_row = act.Range("Z1")
    
    act.Rows(bot_row & ":" & bot_row + (5)).Insert Shift:=x1ShiftDown
    act.Range("A3:J8").Copy
    act.Range("A" & bot_row & ":J" & bot_row + (5)).PasteSpecial xlPasteFormats
    act.Range("A" & bot_row & ":J" & bot_row + (5)).PasteSpecial xlPasteFormulas
    Range("B" & bot_row & ":B" & bot_row + (5)).ClearContents
    
    Application.CutCopyMode = False
    
End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
I got it....

Here is the updated code:
VBA Code:
Sub Add_Job()
    
    Dim act As Worksheet
    Set act = ThisWorkbook.ActiveSheet
    bot_row = act.Range("Z1")
    
    act.Range("A" & bot_row & ":J" & bot_row + (5)).Insert Shift:=xlShiftDown
    act.Range("A3:J8").Copy
    act.Range("A" & bot_row & ":J" & bot_row + (5)).PasteSpecial xlPasteFormats
    act.Range("A" & bot_row & ":J" & bot_row + (5)).PasteSpecial xlPasteFormulas
    Range("B" & bot_row & ":B" & bot_row + (5)).ClearContents
    
    Application.CutCopyMode = False
    
End Sub
 
Upvote 0
Solution
The question regarding deleting column C is still not figured out yet. Any help is appreciated, thanks!
 
Upvote 0
Dummy me i figured this out. When deleting column "c" my referenced cell for bot row got shifted i simply updated the reference cell Z1 after deleting and fixed my issue.
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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