Current VBA is inserting and extra Column

Livin404

Well-known Member
Joined
Jan 7, 2019
Messages
743
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Greetings, my current macro is working as designed, bar one issue I cannot get under control. You will notice in the image a unnecessary Column F which is inserting #N/A. I could come up with a macro deleting the Column, but I have so many macros already. I think the problem is in the array. I much sooner adjust my current one. My current macro "Extract" is: Thank you!

VBA Code:
Sub Boarder()
    Dim rngDB As Range
    Dim rng2 As Range
    Dim rng As Range, Target As Range
    Dim a As Variant, b As Variant
    Dim myDate As Date
    Dim n As Long
        Set rngDB = Range("b1", Range("d" & Rows.Count).End(xlUp))
        Set rngDB = rngDB.SpecialCells(xlCellTypeBlanks)
    rngDB.EntireRow.Insert
    Set rng2 = rngDB.Offset(, 2)
        a = Array("FLIGHT #", "A/C TYPE", "ETD")
    b = Array("", "REMARKS")
    With rng2
        .Value = b
        .Font.Size = 12
        .Font.Name = "Times New Roman"
        .Font.Bold = True
        .Borders(xlEdgeBottom).LineStyle = xlContinuous '<~~cell's botton lines style
        .Borders(xlEdgeBottom).Weight = xlMedium
Capture.JPG
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
The problem is not in array but in the
Set rng2 = rngDB.Offset(, 2)

I think you were trying to define rng2 as column E and F. If so, it is not working. The defined rng2 will become D, E, F. It start with offset 2 from B of rngDB and end at offset 2 from end of rngDB. The size is still 3 column like rngDB.
 
Upvote 0
The problem is not in array but in the
Set rng2 = rngDB.Offset(, 2)

I think you were trying to define rng2 as column E and F. If so, it is not working. The defined rng2 will become D, E, F. It start with offset 2 from B of rngDB and end at offset 2 from end of rngDB. The size is still 3 column like rngDB.
I thought about that. I changed the 2 to a 1 and it did go to only Column D but rather than putting REMARKS in Column D it has #NA. So frustrating.
 
Upvote 0
I thought about that. I changed the 2 to a 1 and it did go to only Column D but rather than putting REMARKS in Column D it has #NA. So frustrating.
You were actually offsetting the rngDB and defined it as rng2
 
Upvote 0
See if this does what you need. I have the dropped the blank element out of the array, you didn't seem to be using it (if this is the case it doesn't actually need to be an array)

VBA Code:
    Set rng2 = Intersect(rngDB.Offset(, 1), Columns("E"))
    b = Array("REMARKS")
 
Upvote 0
Solution
See if this does what you need. I have the dropped the blank element out of the array, you didn't seem to be using it (if this is the case it doesn't actually need to be an array)

VBA Code:
    Set rng2 = Intersect(rngDB.Offset(, 1), Columns("E"))
    b = Array("REMARKS")
I believe a blank cell before REMARKS is intended

He can just
Set rng2 = Range("Ex", Range("Fx") ... x for whatever row

This will solve the problem
 
Upvote 0
See if this does what you need. I have the dropped the blank element out of the array, you didn't seem to be using it (if this is the case it doesn't actually need to be an array)

VBA Code:
    Set rng2 = Intersect(rngDB.Offset(, 1), Columns("E"))
    b = Array("REMARKS")
Thank you that works perfect at least I think it does. Thank you both for taking your time you both help very much.
 
Upvote 0

Forum statistics

Threads
1,214,974
Messages
6,122,536
Members
449,088
Latest member
RandomExceller01

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