Excel/VBA coding


Screen shot
Screen shot  

Screen shot
Screen shot  
Hi Aidan,

I am stuck in a VBA coding and expecting you to help me in resolving the same.
I have 6 sheets in workbook and on sheet1 in range B4:F4 have updated rest of the sheets name. My macro copy the last column range from sheet2 to sheet6 and pasting on sheet1 under unmatched header. please help me to copy range from the relevant sheet and paste under relevant header on sheet1. Here is my code:-

Sub CopyRng()
Dim LCol, LColumns As String
Dim i, j As Variant
Dim cell As Range
Dim sht As String
Dim Sh As Worksheet

LastColumn = Sheet1.Cells(4, Columns.Count).End(xlToLeft).Column

For i = 2 To LastColumn
For j = 5 To 16

LastCol = ActiveSheet.Cells(4, Columns.Count).End(xlToLeft).Column

sht = ActiveSheet.Cells(j, LastCol).Value
Worksheets("Sheet1").Cells(j, i).Value = sht

Next j
Next i
End Sub
Another code which can select the relevant sheet based on value in a range:-

Sub relevantsht()
Dim cell As Range
Set rng = Sheet1.Cells(4, Columns.Count).End(xlToLeft)

For Each cell In rng
LastCol = ActiveSheet.Cells(4, Columns.Count).End(xlToLeft).Column
Next cell

End Sub

I always have problems with the screen shots - not your fault, my eyesight I think - but it makes it hard to see what it is you are having problems with - could you send me an example file and I can then code it for you - my email is aidan.heritage@virgin.net
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here


All Answers

Answers by Expert:

Ask Experts


Aidan Heritage


I have provided first hand support since `95 for Microsoft Office majoring in Word and Excel - support for all versions from 2 onwards. I'm based in the UK, so please allow for time differences when asking me questions from other parts of the world!


My background is in the insurance industry and call centre areas, but have been called upon to provide many varied solutions.

I'm educated to UK A level standard, but as I left school some 30 years ago that is rather irrelevent - university of life has provided more of a background!

©2016 About.com. All rights reserved.