Strange Formatting Issue VBA data import

ChrisBrown

New Member
Joined
Apr 8, 2021
Messages
3
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
Hi, Please be gentle this is my first post on here.
I have an Excel Spreadsheet (XLSM) which imports data from a database using named ranges. All but one work perfectly well.

The problem lies in one which is importing a table of data, starting from a particular cell. When the import is run the formats is applied correctly to the imported data. However the format is also applied to another sheet in the workbook and this is causing a problem for the remainder of the calculations. Even more strangely on the format for the first column is copied.

I have checked all named ranges and all data validations to ensure there is no cross over and also deleted the offending sheet, named range and recreated (with different names) - nothing seems to work

Any thoughts on what may be causing this? Is more info needed?

The offending code is
Range(nm.Name).CopyFromRecordset adoRs

adoRs contains the data.
nm is the name of the range which in this case is "Prices!$B$4"

The sheet where the format is changing is called "Inputs"
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Do you have more than one sheet selected at the time?
 
Upvote 0
When the VBA runs the "Inputs" sheet is the selected one. The full process imports 10 tables to different sheets and about 80 other individual values.
All the other tables import without a problem, its just this one - of the 10 its the second one that is run.
 
Upvote 0
Thanks for a pointer, I have solved it using:-
Sheets(nm.RefersToRange.Parent.Name).Activate
before I populate the range.

No idea why the others work and this one doesn't, a bit odd. But using this code has solved the problem.
 
Upvote 0
Solution

Forum statistics

Threads
1,214,832
Messages
6,121,853
Members
449,051
Latest member
excelquestion515

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