Manipulate the appearance of a spreadsheet in VBA

CaptainGravyBum

Board Regular
Joined
Dec 1, 2023
Messages
77
Office Version
  1. 365
Platform
  1. Windows
Hello,
Hope you can help. I have data which has to be copied into Excel for an import and I need to find a way to manipulate the sheet to show only the required data in each row.
The number of rows will change every time this is pasted in and I need the Customer Code shown in B1 and B5 to appear to the left of each Con No row. The header rows need to be removed as well if possible, because I can add them in at the top if needed. Customer ref should always be in column B, but if copied incorrectly could appear in Column A, so something to cover both eventualities would be beneficial.
Oh, and when the row containing the Customer Code has been used, it can also be removed.

I'm not sure how to write a macro to find the cells with customer ref and insert the information on the rows where it is needed.


1706613942081.png


Sorry it's just an image, my company policies do not allow the XL2BB Add-in to run.
 
Last edited:
Could you please upload a copy of the file that is generating the error?
 
Upvote 0

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
I have uploaded the source file here and I think I now know what the problem is. When the data is exported it usually has a couple of pictures that didn't show in my first file, these are copied across even when I paste values only and they are stopping the macro from running.
If I delete them, it works fine.
I have included the pictures in the latest file, I did try to do something like Activesheet.Shapes.Delete after the file is pasted, but it doesn't do anything.
 
Upvote 0
I believe that the shapes are not the problem. What seems to be the problem is the text "#VALUE!" in cell A8. I deleted that text without deleting the shape and the macro worked properly.
 
Upvote 0
Hi @mumps
I ran some more tests and found that the "image" as I thought it was, actually showed in reality as a formula.

I've used the following code to find and remove those items before running the script you provided:

Dim ws As Worksheet
Dim cell As Range

' Set the worksheet
Set ws = ActiveSheet ' You can change this to reference a specific worksheet if needed

' Loop through each cell in the worksheet
For Each cell In ws.UsedRange
' Check if the cell formula is "Picture"
If cell.FormulaR1C1 = "Picture" Then
' Clear the contents of the cell
cell.ClearContents
End If
Next cell

Seems to do the job, thanks again for your help.
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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