Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
393 views
in Technique[技术] by (71.8m points)

excel - How can I highlight a cell and move this cell over 3 columns using VBA?

I need to move a cell value to the right 3 columns and highlight this cell in the process.

I'm able to move a cells contents over 3 columns using the below formula:

With Sheets("Sheet1").Cells(22, lastColAmt).MergeArea: .Cut .Offset(0, 3):
End With

I set lastColAmt is equal to the last used column in this row.

However, i'm unable to figure out how to highlight this cell (either prior to moving and then moving with the cell value and highlight or after move to new cell, three columns away but in the same row).

I've tried just adding ".Interior.Color = 65535" or trying to select this cell using another formula but nothing I try moves both the cell value and the highlight. Does anyone know how I can do this?

thank you!

question from:https://stackoverflow.com/questions/65645483/how-can-i-highlight-a-cell-and-move-this-cell-over-3-columns-using-vba

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Did you try Sheets("Sheet1").Cells(22, lastColAmt).Interior.Color = 65535 the line before the With? That worked for me.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...