Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old July 21st, 2005, 08:16 PM
nekoukdg nekoukdg is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 3 nekoukdg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 9 sec
Reputation Power: 0
Challenging Excel Macro Help

Hi,
I posted this in another forum but thought I might have a little more luck in this one.

I'm trying to transpose up to 400 rows of data to columns. I'm stuck though, as this is way out of my league.

Perhaps the best way to show what I'm trying to accomplish is in the attached (zipped) spreadsheet. The attached Excel workbook has a demo of what my source data would look like, and then what I want the data to look like after the Macro does its job.

This is complicated, I'm afraid, so I will go into more detail:

Step 1: From the "source" sheet, I'd like the cell range (A2 to I2) copied into the first 25 rows of the "after" sheet. So the data in (A2 to I2) from the source sheet will be pasted into the cell range from (A2 to I2) to (A26 to I26) of the after sheet. Then, the same thing for the second set of data. Data from source sheet cells (A6 to I6) pasted to the cell range on the after sheet from (A27 to I27) to (A51 to I51) the source sheet copied to the next 25 rows of the after sheet, and so on. I'd like this to occur for up to 400 sets of this type of data on the source sheet.

Step 2: Similar functionality to Step 1. Take source sheet data from cells (AJ2 to AQ2) and paste into the range of after sheet cells from (P2 to W2) to (P26 to W26). Repeat for source cells (AJ6 to AQ6), pasting that data into the after sheet cell range from (P27 to W27) to (P51 to W51). Repeat, again, for up to 400 sets of this type of data from the source sheet.

Step 3: Transpose source sheet cells (K1 to AI1) to after sheet cells (J2 to J26). Repeat this for the next set of data, so transpose source sheet cells (K5 to AI5) to after sheet cells (J27 to J51). Repeat, again, for up to 400 sets of this type of data from the source sheet.

Step 4: Similar functionality to Step 3. Transpose source sheet cells (K2 to AI2) to after sheet cells (K2 to K26). Repeat this for the next set of data, so transpose source sheet cells (K6 to AI6) to after sheet cells (K27 to K51). Repeat, again, for up to 400 sets of this type of data from the source sheet.

Step 5: Similar functionality again. Transpose source sheet cells (K3 to AI3) to after sheet cells (L2 to L26). Repeat this for the next set of data, so transpose source sheet cells (K7 to AI7) to after sheet cells (L27 to L51). Repeat, again, for up to 400 sets of this type of data from the source sheet.

Step 6: Similar functionality yet again. Transpose source sheet cells (K4 to AI4) to after sheet cells (M2 to M26). Repeat this for the next set of data, so transpose source sheet cells (K8 to AI8) to after sheet cells (M27 to M51). Repeat, again, for up to 400 sets of this type of data from the source sheet.

That's it! Maybe I'm making this harder than it is... but can anyone out there please help me?

Thanks!
Attached Files
File Type: zip demo_spreadsheet_for_conversion.zip (17.1 KB, 49 views)

Reply With Quote
  #2  
Old July 28th, 2005, 02:32 PM
mikewbrown mikewbrown is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: Vancouver, BC
Posts: 12 mikewbrown User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 57 m 53 sec
Reputation Power: 0
Will each section always be 3 lines?

Reply With Quote
  #3  
Old July 28th, 2005, 02:57 PM
mikewbrown mikewbrown is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: Vancouver, BC
Posts: 12 mikewbrown User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 57 m 53 sec
Reputation Power: 0
I will assume that the format doesn't change at all. Here is the code that I would build, you might want to add error handling to it and improve the structure though...

Sub test_mac()

Dim sec1_array()
Dim sec2_array()
ReDim sec1_array(9)
ReDim sec2_array(8)
Dim c1 As String
Dim c2 As String


Sheets("demo_source_data_sheet").Activate

n = 2
w = 2

Do Until Cells(n, 1) = ""
Sheets("demo_source_data_sheet").Activate
sec1_array = Range(Cells(n, 1), Cells(n, 9))
sec2_array = Range(Cells(n, 36), Cells(n, 43))
c1 = Right(Cells(n + 1, 9), Len(Cells(n + 1, 9)) - 4)
c2 = Right(Cells(n + 2, 9), Len(Cells(n + 2, 9)) - 4)
Range(Cells(n - 1, 11), Cells(n + 2, 35)).Copy
Sheets("demo_sheet_after_macro_conversn").Activate
Cells(w, 10).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=True
Range(Cells(w, 1), Cells(w + 24, 9)) = sec1_array
Range(Cells(w, 16), Cells(w + 24, 23)) = sec2_array
Cells(w, 14) = c1
Cells(w, 15) = c2
n = n + 4
w = w + 25
Sheets("demo_source_data_sheet").Activate
Loop

Application.CutCopyMode = False


End Sub

Reply With Quote
  #4  
Old July 28th, 2005, 03:20 PM
nekoukdg nekoukdg is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 3 nekoukdg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 9 sec
Reputation Power: 0
Follow up question...

Thanks SO MUCH, Mike!

But it's getting stuck on declaring the variable at the line:

c1 = Right(Cells(n + 1, 9), Len(Cells(n + 1, 9)) - 4)

Looks like it coud work though. What do you think?

Reply With Quote
  #5  
Old July 28th, 2005, 03:56 PM
mikewbrown mikewbrown is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: Vancouver, BC
Posts: 12 mikewbrown User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 57 m 53 sec
Reputation Power: 0
This might be where you need error handling. If the cell is blank or less than 4 characters in length an error will pop up. Perhaps adding an If len(cells(n,x)) > 4 then would fix it.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Challenging Excel Macro Help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT