Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Couple subs need help with

Hi guys,

I'm trying to write a couple subs in vba. One needs to find any nonzero value from column H in multiple sheets and transfer its value plus any values in its row (cells A-G) to the first sheet in the workbook. The second needs to search for matching strings (inventory items) in column A (since I will have multiple entries of the inventory items) of one workbook and sum their integers from column D (inventory total). I would like to then transfer the inventory item and the sum inventory total onto another sheet. I realize this code would be very complicated so even a jumping off point would be greatly appreciated. Thanks in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default Couple subs need help with

Richard Bridges wrote:

I'm trying to write a couple subs in vba. One needs to find any nonzero
value from column H in multiple sheets and transfer its value plus any
values in its row (cells A-G) to the first sheet in the workbook.


I assume that "transfer its value" means "copy the value", so... here's
this one:

Sub findNonzeros()
For L0 = 2 To Sheets.Count
For L1 = 1 To Sheets(L0).Cells.SpecialCells(xlCellTypeLastCell). Row
If Sheets(L0).Cells(L1, 8).Value < 0 Then
x = Sheets(1).Cells.SpecialCells(xlCellTypeLastCell).R ow + 1
For L2 = 1 To 8
Sheets(1).Cells(x, L2).Value = Sheets(L0).Cells(L1, L2).Value
Next
End If
Next
Next
End Sub

If Sheets(1) isn't where you want the data copied, change the 1 to the name
of the sheet (e.g. Sheets("target sheet")).

The second needs to search for matching strings (inventory items) in
column A (since I will have multiple entries of the inventory items) of
one workbook and sum their integers from column D (inventory total). I
would like to then transfer the inventory item and the sum inventory
total onto another sheet. I realize this code would be very complicated
so even a jumping off point would be greatly appreciated.


Try this:

Sub matchInventory(what As String, where As Worksheet)
Dim wks As Worksheet
For Each wks In Sheets
If Not (wks Is where) Then
For L0 = 1 To wks.Cells.SpecialCells(xlCellTypeLastCell).Row
'case-sensitive
If (what) = wks.Cells(L0, 1).Value Then
'case-insensitive
'If LCase$(what) = LCase$(wks.Cells(L0, 1).Value) Then
v = v + wks.Cells(L0, 4).Value
End If
Next
End If
Next
x = where.Cells.SpecialCells(xlCellTypeLastCell).Row + 1
where.Cells(x, 1).Value = what
where.Cells(x, 2).Value = v
End Sub

You'll need to call it like this:

matchInventory "Item Name", Sheets("inventory totals")

One line for every inventory item (and change "inventory totals" to the
actual name of the target sheet). If you have some way of automatically
getting the inventory items, you can loop through this, somewhat like so:

Do
x = getNextInventoryItem
If Len(x) Then
matchInventory "Item Name", Sheets("inventory totals")
Else
Exit Do
End If
Loop


Note that for both findNonzeros() and matchInventory(), if you start with a
completely blank target worksheet ("Sheets(1)" in findNonzeros() and
"where" in matchInventory()), you'll end with the top row empty. Shrug.

--
At this point I have big dent in my office
wall exactly matching the shape of my head.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Couple subs need help with

Thanks, Auric.

I'll apply the code and see what happens.

Richard
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
couple of questions cjbarron5 Excel Discussion (Misc queries) 10 June 2nd 08 01:46 AM
Couple of Questions Need Help Please..... Jeremy Excel Discussion (Misc queries) 0 February 8th 08 06:11 PM
A couple of questions [email protected] Excel Discussion (Misc queries) 3 November 22nd 06 03:39 AM
Couple of Questions Toysforfids Excel Discussion (Misc queries) 4 September 14th 06 05:20 AM
There are a couple of parts to this ???...Thank you for the help. Pete Petersen Excel Worksheet Functions 0 December 30th 04 02:45 PM


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

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

About Us

"It's about Microsoft Excel"