PC Review


Reply
Thread Tools Rate Thread

How to check and skip column during paste

 
 
choo
Guest
Posts: n/a
 
      12th Oct 2009
Hi,
I have this macro to copy a row of data from shtB(bkData) to shtA(bkMaster),
if we find the part number

we want shtB. This is fairly straight forward.



If Trim(shtB.Cells(irow2, 1)) = PartNo Then
Fnd = True
shtB.Cells(irow2, 2).Resize(1, 12).Copy
bkMaster.ActiveSheet.Cells(irow + 2, 3).PasteSpecial
Paste:=xlPasteValues
End If



The original format in Excel file looks like this:
--------------------------------------------------
A B C D E F G H I J K
PartNo wk3 wk4 wk5 wk6 wk7 wk8 wk9 wk10 wk11 wk12


New column added in between work weeks:
---------------------------------------
A B C D E F G H I J K ...
PartNo wk3 wk4 Total wk5 wk6 wk7 wk8 Total wk9 wk10 ...



Now the bkMaster has added a few new columns in between. The column heading
is named "Total".

What I would like the program to do is that before the .pastespecial
command, the code will check the

heading in Row1. So that data from ShtB will be copied to the correct
column in shtA.

If heading = "wk" & some numbers, then paste the data.
If heading <> start with "wk", then it will skip/jump to the next column,
check the heading again,
if heading = "wk" & some numbers, then continue to paste the next piece of
data.


I don't know how do this in proper VBA code. Can someone help, please?

Thank you in advance.
 
Reply With Quote
 
 
 
 
Jacob Skaria
Guest
Posts: n/a
 
      12th Oct 2009
Try the below

Dim lngCol As Long, intCount As Integer

If Trim(shtB.Cells(irow2, 1)) = PartNo Then
Fnd = True
lngCol = 2
Do
If bkmaster.ActiveSheet.Cells(1, lngCol) Like "wk*" Then
intCount = intCount + 1
bkmaster.ActiveSheet.Cells(irow + 2, lngCol) = _
shtB.Cells(irow2, 2).Resize(1, 12).Cells(intCount)
End If
lngCol = lngCol + 1
Loop Until bkmaster.ActiveSheet.Cells(1, lngCol) = ""
End If

If this post helps click Yes
---------------
Jacob Skaria


"choo" wrote:

> Hi,
> I have this macro to copy a row of data from shtB(bkData) to shtA(bkMaster),
> if we find the part number
>
> we want shtB. This is fairly straight forward.
>
>
>
> If Trim(shtB.Cells(irow2, 1)) = PartNo Then
> Fnd = True
> shtB.Cells(irow2, 2).Resize(1, 12).Copy
> bkMaster.ActiveSheet.Cells(irow + 2, 3).PasteSpecial
> Paste:=xlPasteValues
> End If
>
>
>
> The original format in Excel file looks like this:
> --------------------------------------------------
> A B C D E F G H I J K
> PartNo wk3 wk4 wk5 wk6 wk7 wk8 wk9 wk10 wk11 wk12
>
>
> New column added in between work weeks:
> ---------------------------------------
> A B C D E F G H I J K ...
> PartNo wk3 wk4 Total wk5 wk6 wk7 wk8 Total wk9 wk10 ...
>
>
>
> Now the bkMaster has added a few new columns in between. The column heading
> is named "Total".
>
> What I would like the program to do is that before the .pastespecial
> command, the code will check the
>
> heading in Row1. So that data from ShtB will be copied to the correct
> column in shtA.
>
> If heading = "wk" & some numbers, then paste the data.
> If heading <> start with "wk", then it will skip/jump to the next column,
> check the heading again,
> if heading = "wk" & some numbers, then continue to paste the next piece of
> data.
>
>
> I don't know how do this in proper VBA code. Can someone help, please?
>
> Thank you in advance.

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MACRO PASTE CELL to COLUMN, SKIP ROWS Dan Microsoft Excel Misc 1 2nd Feb 2010 01:03 PM
Spell check -- text marked skip spelling and grammar check =?Utf-8?B?RGF2aWQgQS4=?= Microsoft Word Document Management 8 9th Aug 2008 11:47 PM
RE: hide one column skip two column and unhide one of 11 =?Utf-8?B?SkxHV2hpeg==?= Microsoft Excel Programming 0 11th Jan 2007 02:59 AM
RE: paste formula and skip blanks Sean Microsoft Excel Misc 4 6th Apr 2006 07:02 PM
Paste Special - Skip Blanks Bonnie Microsoft Excel Misc 1 4th Mar 2005 01:01 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:42 PM.