Help Required Amending Some VBA Code

purceld2

Well-known Member
Joined
Aug 18, 2005
Messages
549
I have a bit of VBA code which I obtain of this BB and it works fine on the sample Spreadsheet below but I am trying to amended to work on a slightly different SS and also introduce some flexibility to the code.

The code below works fine on this SS


Excel Workbook
ABCDEFGHIJKLMNOPQRSTU
1Venue CodeSlot 1Slot 2Slot 3Slot 4Slot 5Slot 6Slot 1Slot 2Slot 3Slot 4Slot 5Slot 6Slot 1Slot 2Slot 3Slot 4Slot 5Slot 6Slot 1Slot 2
210013514511514511511
310023511511511
410024514511514511511
510030514511514511511
610031514511514511511
710033233233233511233233233511233233233511233233
810036514511514511511
910044514511514511511
1010056514511514511511
1110057514511514511511
1210066514511514511511
1310070233233233514233233233514233233233233233
1410072514511514511511
1510073514511514511511
Sheet1


I am trying to amend the code to work on the SS below amending the code to invite the user to enter a date then the code would move along row 1 to find the corresponding date. Then the column that is slot 1 would be the starting point for the VBAcode. It would then summerise the data contained in slot 1 to 6 for the date entered.

Excel Workbook
ABCCCDCECFCGCHCICJCKCLCMCNCOCPCQCRCSCTCUCVCWCXCYCZ
1Lookup Date30/08/201026/07/201002/08/201009/08/201016/08/2010
2Venue CodeCount123456123456123456123456
12133085042SHELL708741741736708SHELL741741736708SHELL741741SHELL708
12373478142SHELL708741741736708SHELL741741736708SHELL741741SHELL708
12383478252SHELL708741741736708SHELL741741736708SHELL741741SHELL708
12463479122SHELL708741741736708SHELL741741736708SHELL741741SHELL708
12483479362SHELL708741741736708SHELL741741736708SHELL741741SHELL708
15846203872SHELL708741741736708SHELL741741736708SHELL741741SHELL708
Venue Availability Checker


Code that needs amending

[face=Courier New]Sub Count_Slot_Items()
Dim LastRow As Long

Application.ScreenUpdating = False

With Sheets("Sheet2")

.Columns("A:L").Clear

For c = 0 To 10 Step 2

Sheets("Sheet1").Columns("B:B").Offset(, c / 2).Copy Destination:=.Range("B1").Offset(, c)

.Columns("B:B").Offset(, c).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=.Range("A1").Offset(, c), Unique:=True
.Columns("B:B").Offset(, c).Clear
LastRow = .Range("A" & Rows.Count).Offset(, c).End(xlUp).Row

.Range("B1").Offset(, c).Value = "Count"
If LastRow > 1 Then
.Range("B2").Offset(, c).Formula = "=COUNTIF(Sheet1!" & Columns(2 + c / 2).Address & "," & Range("A2").Offset(, c).Address(0, 0) & ")"
If LastRow > 2 Then
.Range("B2").Offset(, c).AutoFill Destination:=.Range("B2:B" & LastRow).Offset(, c)
End If
.Range("B2:B" & LastRow).Offset(, c).Value = .Range("B2:B" & LastRow).Offset(, c).Value
End If

Next c

' Format cells
Range("A1").Copy
Range("A1", Range("A1").End(xlToRight)).PasteSpecial Paste:=xlPasteFormats
.Select

End With

Application.ScreenUpdating = True

End Sub
[/face]
 

Some videos you may like

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,861
Messages
5,513,834
Members
408,972
Latest member
TDotHanny

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top