Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Select Non-Contiguous Cells and Loop


Hello Friends,

I am new here and new to Excel Programming too. I have a issue.

In Employee1 workbook, I have many employee records with first name,
last name, title, ssn ......., year 1, amount 1, year 2, amount 2 ..
columns.

My issue is to copy these specific records from the above workbook and
paste it in a new workbook so that the year and amount are shown
individually for every employee.

Sample:

FName LName Title SSN Gender DOB Address1 .. .. Year1 Amount1 Year2.
Bourne Cyber Mr 123 M 1/1/01 jj 1991 20000 1992

I need the output format in a different file as

Fname Lname Title SSN Year1 Amount1
Fname Lname Title SSN Year2 Amount2
Fname Lname Tilte Ssn Year3 Amount3
Fname2 Lname2 Title2 SSN2 Year1 Amount1
Fname2 Lname2 Title2 SSN@ Year2 Amount2


This is just a sample , It may contain many records. Basically i need
to loop it.

Please Help.
Urgent.

Abhi
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Select Non-Contiguous Cells and Loop

yuo can do this if you create a pivot table...might be easier for you than
writing VBA code.

"abhishek" wrote:


Hello Friends,

I am new here and new to Excel Programming too. I have a issue.

In Employee1 workbook, I have many employee records with first name,
last name, title, ssn ......., year 1, amount 1, year 2, amount 2 ..
columns.

My issue is to copy these specific records from the above workbook and
paste it in a new workbook so that the year and amount are shown
individually for every employee.

Sample:

FName LName Title SSN Gender DOB Address1 .. .. Year1 Amount1 Year2.
Bourne Cyber Mr 123 M 1/1/01 jj 1991 20000 1992

I need the output format in a different file as

Fname Lname Title SSN Year1 Amount1
Fname Lname Title SSN Year2 Amount2
Fname Lname Tilte Ssn Year3 Amount3
Fname2 Lname2 Title2 SSN2 Year1 Amount1
Fname2 Lname2 Title2 SSN@ Year2 Amount2


This is just a sample , It may contain many records. Basically i need
to loop it.

Please Help.
Urgent.

Abhi

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Select Non-Contiguous Cells and Loop

try this:

Option Explicit
Sub Main()

Dim ThisRow As Long
Dim ThisCol As Long
Dim ThisCol14 As Long
Dim wsActive As Worksheet
Dim wsOut As Worksheet
Dim OutRow As Long

Set wsActive = ActiveSheet
Set wsOut = Worksheets.Add ' for output

'start loop at row 2 if row 1 is table headings
With wsActive
For ThisRow = 2 To .Range("A2").End(xlDown).Row
ThisCol = 8 ' first col of Year1
Do
OutRow = OutRow + 1
'get first 4 items
For ThisCol14 = 1 To 4
wsOut.Cells(OutRow, ThisCol14) = .Cells(ThisRow, ThisCol14)
Next
wsOut.Cells(OutRow, 5) = .Cells(ThisRow, ThisCol)
wsOut.Cells(OutRow, 6) = .Cells(ThisRow, ThisCol + 1)

ThisCol = ThisCol + 2
Loop Until .Cells(ThisRow, ThisCol) = ""

Next ' next record
End With

End Sub


adds a new sheet for the output
reads each row of the activesheet
places first four items of each row in the active sheet fro each pair of
year/amounts





"Patrick Molloy" wrote:

yuo can do this if you create a pivot table...might be easier for you than
writing VBA code.

"abhishek" wrote:


Hello Friends,

I am new here and new to Excel Programming too. I have a issue.

In Employee1 workbook, I have many employee records with first name,
last name, title, ssn ......., year 1, amount 1, year 2, amount 2 ..
columns.

My issue is to copy these specific records from the above workbook and
paste it in a new workbook so that the year and amount are shown
individually for every employee.

Sample:

FName LName Title SSN Gender DOB Address1 .. .. Year1 Amount1 Year2.
Bourne Cyber Mr 123 M 1/1/01 jj 1991 20000 1992

I need the output format in a different file as

Fname Lname Title SSN Year1 Amount1
Fname Lname Title SSN Year2 Amount2
Fname Lname Tilte Ssn Year3 Amount3
Fname2 Lname2 Title2 SSN2 Year1 Amount1
Fname2 Lname2 Title2 SSN@ Year2 Amount2


This is just a sample , It may contain many records. Basically i need
to loop it.

Please Help.
Urgent.

Abhi

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ctrl+Click doesn't select non contiguous cells Rafeek Excel Discussion (Misc queries) 0 August 12th 11 02:33 PM
Select non-contiguous cells in Excel 2007 Compu Geek Excel Discussion (Misc queries) 3 October 23rd 09 02:00 PM
Copy and Paste LAST ROW of data: non-contiguous Row, contiguous Column Sam via OfficeKB.com Excel Programming 8 November 5th 07 07:18 PM
counting cells that are 0 in a range of non-contiguous cells Mark Excel Worksheet Functions 9 March 14th 07 02:45 PM
How do I use For loop to pick different Range of cells to Select & Merge? [email protected] Excel Programming 3 February 3rd 07 02:02 AM


All times are GMT +1. The time now is 01:20 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"