Re: User input to update same cell multiple worksheets
nconrad,
I would make all of the other sheets refer to the B3, C3, D3 and C53 values.
That way when ever these values cahnge, teh formula on the other sheets will ensure they get updated too.
Re: User input to update same cell multiple worksheets
nconrad,
I would make all of the other sheets refer to the B3, C3, D3 and C53 values.
That way when ever these values cahnge, teh formula on the other sheets will ensure they get updated too.
Re: text to integer
HAve you tried formatting the number to appear as shown.
Try a custom format like ###-####
Re: Merging workbooks - error message "too many cell formats"
RickM,
The following code I obtained from the web - Sorry I can't remeber the original author - will remove extra cells/rows/columns and formats.
Just be sure to save your work before you do it.
'There is no built-in "compact" option in Excel like the one in Access.
'Have a look at this thread - you will find some code there to get rid of unused rows and columns: 50564
'This is the version I use (copied from somebody else and adapted a bit):
' Remove superfluous rows and columns in each worksheet of the active workbook
Sub CleanUp()
Dim ar As Range, r As Long, c As Integer, tr As Long, tc As Integer
Dim ws As Worksheet, ur As Range, sh As Shape
Dim fc As Boolean, fd As Boolean, fs As Boolean
If ActiveWorkbook Is Nothing Then Exit Sub
On Error Resume Next
Application.ScreenUpdating = False
For Each ws In ActiveWorkbook.Worksheets
Application.StatusBar = "Checking " & ws.Name & ", be patient please..."
fc = ws.ProtectContents
fd = ws.ProtectDrawingObjects
fs = ws.ProtectScenarios
ws.Unprotect
r = 0
c = 0
Set ur = Union(ws.UsedRange.SpecialCells(xlCellTypeConstants), _
ws.UsedRange.SpecialCells(xlCellTypeFormulas))
If Err = 1004 Then
Err.Clear
Set ur = ws.UsedRange.SpecialCells(xlCellTypeConstants)
End If
If Err = 1004 Then
Err.Clear
Set ur = ws.UsedRange.SpecialCells(xlCellTypeFormulas)
End If
If Err = 0 Then
For Each ar In ur.Areas
tr = ar.Range("A1").Row + ar.Rows.Count - 1
tc = ar.Range("A1").Column + ar.Columns.Count - 1
If tc > c Then c = tc
If tr > r Then r = tr
Next
For Each sh In ws.Shapes
tr = sh.BottomRightCell.Row
tc = sh.BottomRightCell.Column
If tc > c Then c = tc
If tr > r Then r = tr
Next
ws.Rows(r + 1 & ":" & ws.Rows.Count).Delete
ws.Range(ws.Cells(1, c + 1), ws.Cells(1, 256)).EntireColumn.Delete
Else
Err.Clear
End If
ws.Protect DrawingObjects:=fd, Contents:=fc, Scenarios:=fs
Next
Set ar = Nothing
Set ur = Nothing
Set ws = Nothing
Application.StatusBar = False
Application.ScreenUpdating = True
MsgBox "Superfluous rows and columns have been removed.", vbInformation
End Sub
Display More
Over time, you may also accumulate a lot of custom number formats. I use the following code to get rid of them, based on an example by John Walkenbach:
' Remove unused custom number formats.
' Remark: only checks cells in worksheets.
' Doesn't check charts, so any formats used in charts but not in cells will be removed.
' Uses SendKeys, which can cause problems.
Sub DeleteFormats()
Dim strOldFormat As String
Dim strNewFormat As String
Dim aCell As Range
Dim sht As Worksheet
Dim strFormats() As String
Dim fFormatsUsed() As Boolean
Dim i As Integer, j As Integer, k As Integer
If ActiveWorkbook.Worksheets.Count = 0 Then
MsgBox "The active workbook contains no worksheets.", vbInformation
Exit Sub
End If
On Error GoTo Exit_Sub
Application.Cursor = xlWait
ReDim strFormats(1000)
ReDim fFormatsUsed(1000)
Set aCell = Range("A1")
aCell.Select
strOldFormat = aCell.NumberFormatLocal
aCell.NumberFormat = "General"
strFormats(0) = "General"
strNewFormat = aCell.NumberFormatLocal
i = 1
Do
' Dialog box requires local format
SendKeys "{TAB 3}{DOWN}{ENTER}"
Application.Dialogs(xlDialogFormatNumber).Show strNewFormat
strFormats(i) = aCell.NumberFormat
strNewFormat = aCell.NumberFormatLocal
i = i + 1
Loop Until strFormats(i - 1) = strFormats(i - 2)
aCell.NumberFormatLocal = strOldFormat
ReDim Preserve strFormats(i - 2)
ReDim Preserve fFormatsUsed(i - 2)
For Each sht In ActiveWorkbook.Worksheets
For Each aCell In sht.UsedRange
For i = 0 To UBound(strFormats)
If aCell.NumberFormat = strFormats(i) Then
fFormatsUsed(i) = True
Exit For
End If
Next i
Next aCell
Next sht
' Prevent error on built-in formats
On Error Resume Next
For i = 0 To UBound(strFormats)
If Not fFormatsUsed(i) Then
' DeleteNumberFormat requires international format
ActiveWorkbook.DeleteNumberFormat strFormats(i)
End If
Next i
Exit_Sub:
Set aCell = Nothing
Set sht = Nothing
Erase strFormats
Erase fFormatsUsed
Application.Cursor = xlDefault
End Sub
'Warning: always save a backup of your worksheet before "cleaning" it!
Display More
Re: insert a row using VBA
Inung,
Could you please supply a sample workbook showing what you want?
Re: insert a row using VBA
Inung,
You are right, the pivot table needs to be refreshed.
This is done by right clicking in a cell inside the pivot table and sleecting refresh data, or by selecting the refresh data control on the pivot table toolbar, or using the refresh data control ont he data menu.
Alternatively, you can have it done automatically with something like this
Option Explicit
Private Sub Worksheet_Activate()
Dim pt As PivotTable
For Each pt In ActiveSheet.PivotTables
pt.RefreshTable
Next
End Sub
Display More
the code will need to be placed in the worksheet that contains the pivot table.
Blaine,
Are the subtotal lines evenly spaced?
If not is there any common text on the subtotal lines that can be used to identifiy it?
Inung,
If you add another cloumn to your data with the formula =weeknum(date).
Then a pivottable will do the work for you.
You will need to use a dynamic range as the source data for the pivot table as in the attached example.
Andy,
That is a much more elegant solution.
Thanks
Inung,
Where do you want to insert the row? A sample of the sheet would help.
ascalese,
I learnt 'this stuff' through making mistakes, just like anyone else.
Along the way, I found out about the various boards and found them invaluable, not just for posting questions, but there are a large number of very clever people contributing to them.
Their solutions also help a lot.
Where I can, I try to repay in kind.
As far as books go, I could not offer any real suggestions as I have not bought any, however if you look around the forum, there are plenty of good references. (Dont forget Dave Hawley's books too - it must be good, he owns this place and doesn;t live that far from me too!)
As far as releasing memory in VBA, it is nt really necesary unless you are dealing with objects, then you should 'Set ObjectName= Nothing" at the end of their usefulness to realease memory. VBA 'normally' cleans the rest up for you as you exit the routine. As you seem to realise however, it is good programming practice to explicitly release the memory anyway.
There may be a few other conditions on this, maybe other readers will be able to help.
Of course you are right, I should have not been so hasty in the cut&paste job. Sorry about that.
As I said - untested - and it showed.
Try this (untested)
Option Explicit
Sub SelectSheets()
Dim ws As Worksheet
Dim c As Chart
Dim SheetsArray()
Dim Counter As Integer
For Each ws In ActiveWorkbook.Worksheets
If ws.Name Like "DS*" Then
ReDim Preserve SheetsArray(Counter)
SheetsArray(Counter) = ws.Name
Counter = Counter + 1
End If
Next ws
For Each c In ActiveWorkbook.Charts
If c.Name Like "DS*" Then ' or any other name etc...
ReDim Preserve SheetsArray(Counter)
SheetsArray(Counter) = c.Name
Counter = Counter + 1
End If
Next ws
Sheets(SheetsArray()).Select
End Sub
Display More
ascalese,
Charts exist in the Charts collection if not embedded, as against the worksheets collection if embedded.
The code will probably need to be amended to go through the charts collection in a similar manner to the worksheets collection.
The results of the debug messages are shown in the immediate window. ( Go to the VBA editor menu option View, option Immediate window.
The results of the test will be visible there. Please let the forum knwo the results.
Et3rnal,
Without looking at the rest of the code, it seems to me that Left never = True for this to happen.
Try adding two debug statements around the
If Left = True Then line
like
debug.print left, "left option test next "
If Left = True Then
debug.print left, "left option selected" and then rerun the procedure and see what the values are.
ascalese
try
Sub SelectSheets()
Dim ws As Worksheet
Dim SheetsArray()
Dim Counter As Integer
For Each ws In ActiveWorkbook.Worksheets
If ws.Name Like "DS*" Then
ReDim Preserve SheetsArray(Counter)
SheetsArray(Counter) = ws.Name
Counter = Counter + 1
End If
Next ws
Sheets(SheetsArray()).Select
End Sub
Display More
Hank,
This is a quick tought, so I may be wrong, but the data looks reasonably formatted.
Why don't you sue the text to columns tool to separate the question number from the answer.
you can then use a pivot table to summarise the responses.
TVSMVP,
You can access the closed workbook and make a local copy of the data for lookup purposes.
an array formula like the following will retreive the values
='file path\file name.xls'!range name
This approach will only work for fixed length arrays.
4508Ginx,
You could either use the date functionsin excel to determine the firtst day of the current mont and and the month after and then subtract the differnce, or create an array that holds the corresponding number of days for each month. As you already have a combo box, I imagine that there must be an array or range that holds these values and you could do this easily. (not allowing for leap years that is, in that event I suggest that you use the 'calendar method')
Could you mean something like this as attached.
I had to manually set the primary and secondary axis values so that the 0 point was the same level on both.