Current VBA is inserting and extra Column

Livin404

Active Member
Joined
Jan 7, 2019
Messages
392
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
 

Some videos you may like

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Zot

Well-known Member
Joined
Nov 26, 2020
Messages
950
Office Version
  1. 2016
Platform
  1. Windows
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.
 

Livin404

Active Member
Joined
Jan 7, 2019
Messages
392
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
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.
 

Zot

Well-known Member
Joined
Nov 26, 2020
Messages
950
Office Version
  1. 2016
Platform
  1. Windows
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
 

Alex Blakenburg

Active Member
Joined
Feb 23, 2021
Messages
372
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

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")
 
Solution

Zot

Well-known Member
Joined
Nov 26, 2020
Messages
950
Office Version
  1. 2016
Platform
  1. Windows
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
 

Livin404

Active Member
Joined
Jan 7, 2019
Messages
392
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,093
Messages
5,622,655
Members
415,917
Latest member
kungsleden

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
Top