Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all 49926 articles
Browse latest View live

Combinations

$
0
0
I found this code online and I modified it to get me somewhat close to what I'm looking for. I have a list of 10 items and I'm looking to print every combination of 6 items (order is irrelevant but they cannot be duplicated). Right now it prints 6 to start and then eventually prints groups of 7,8,9 until it overflows. How do I get it to stop at 6 and not overflow? Thanks I appreciate your help!


Code:

' Set in A1, down. Result in C1, down and across. Clears C:Z.
Sub PowerSet()
Dim vElements As Variant, vresult As Variant
Dim lRow As Long, i As Long
 
vElements = Application.Transpose(Range("A1", Range("A1").End(xlDown)))
Columns("C:Z").Clear
 
lRow = 6
For i = 6 To UBound(vElements)
    ReDim vresult(1 To i)
    Call CombinationsNP(vElements, i, vresult, lRow, 1, 1)
Next i
End Sub
 
Sub CombinationsNP(vElements As Variant, p As Long, vresult As Variant, lRow As Long, iElement As Integer, iIndex As Integer)
Dim i As Long
 
For i = iElement To UBound(vElements)
    vresult(iIndex) = vElements(i)
    If iIndex = p Then
        lRow = lRow + 1
        Range("C" & lRow).Resize(, p) = vresult
    Else
        Call CombinationsNP(vElements, p, vresult, lRow, i + 1, iIndex + 1)
    End If
Next i
End Sub


Automatic sum

$
0
0
Hi,

Is there a macro to automatic sum product from below data in A1:

204733 Corona -90,000.00 110 Flippy Coin 1,301 Riva Flippy Hour
204091 San Miguel Large -90,000.00 110 Flippy Coin 1,301 Riva Flippy Hour
204091 San Miguel Large -90,000.00 110 Flippy Coin 1,301 Riva Flippy Hour
204735 Heineken -65,000.00 110 Flippy Coin 1,301 Riva Flippy Hour
204735 Heineken -65,000.00 110 Flippy Coin 1,301 Riva Flippy Hour
204737 San Mig Light -65,000.00 110 Flippy Coin 1,301 Riva Flippy Hour
280145 Casa Lapostolle -155,000.00 110 Flippy Coin 1,301 Riva Flippy Hour
204737 San Mig Light -65,000.00 110 Flippy Coin 1,301 Riva Flippy Hour
204738 Bintang Can -130,000.00 110 Flippy Coin 1,301 Riva Flippy Hour
204094 Anker Large -240,000.00 110 Flippy Coin 1,301 Riva Flippy Hour
204094 Anker Large -160,000.00 110 Flippy Coin 1,301 Riva Flippy Hour
206193 Pepe Lopez Gls -190,000.00 110 Flippy Coin N/A
206193 Pepe Lopez Gls -190,000.00 110 Flippy Coin N/A
206214 Myers Dark Gls -200,000.00 110 Flippy Coin N/A
206214 Myers Dark Gls -200,000.00 110 Flippy Coin N/A
204094 Anker Large -160,000.00 110 Flippy Coin N

The Result will be
C1 : Corona, D1 : 90000
C2 : San Miguel Large, D2 : 180000
C3: Heineken, D3: 130000
C4: San Mig Light, D4: 130000
C5: Casa Lapostolle, D5:155000
C6: Bintang Can, D6: 130000
C7: Anker Large, D7: 560000
C8: Pepe Lopes Gls, D8:380000
C9: Myers Dark Gls, D9:400000

Regards,
Andy
Attached Files

Posting thread in CS area

$
0
0
Need help posting a thread in the CS area

Best Regards,

John

Macro then msgbox

$
0
0
Hi

I have excel formulas in inidvidyal cells A1:B6 that either say "check" if the numbers don't matcg or "ok" if numbers match...I'm trying to make a macro that reads that range...if any one of the cells say "check"...I want the macro to generate a message box that says "numbers must be checked "....could someone pls help me

macro to check for duplicates and copy data if no duplicate found

$
0
0
Hi,

I am trying to write a macro that runs when sheet2 is clicked on. what im tying to get the macro to do is checks all the entries (which are names of people) in sheet 1, column B and looks for duplicates in sheet2 column B. If a duplicate is not found in sheet2, it will copy link all of that row to sheet2. Also, if a cell is found blank in sheet1, to just skip it. I have tried looking in the forum for help but all the codes i find are doing for i=1 and j=1, then loop. From my understanding, this is just checking one cell against another cell and then truncating by one, assuming that the duplicated will fall on the same row. I need a macro that compares each cell with the whole list. Any help would be appreciated. Thank you.

Value thru Message Box

$
0
0
Hello,

Request your to correct the below Code as i am trying to get value thru message box and add the same in the formula

"NDS" is the string which i used to get value thru message box and add the same in the formula.

HTML Code:

Sub Macro1()

Dim NDS As String

Application.ScreenUpdating = False

NDS = InputBox("Enter the number of days from Invoice to calculate Due Date")
   
Range("o2").Select

        ActiveCell.FormulaR1C1 = _
        "=IF(RC[-2]>0,(((RC[-1]-RC[-6])+1)+NDS),(RC[-1]-RC[-6])+1)"
 

    Range("O3").Select
End Sub

Regards,

Prabhu

copy paste code not working

$
0
0
Hello. Can someone let me know why this code isn't working?


Code:

Sub LoopThroughSheets()



For i = 1 To 8
Set sht = ThisWorkbook.Worksheets("Sheet1")
LastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row + 1
ActiveSheet.Range("A").Copy Destination:=Worksheets(sht).Range("A", LastRow)
End Sub

Virus scanner nuking module?? Not a threat, I swear!

$
0
0
See code below (commented out for your safety :rolleyes:), it's just a quick lines of code counter I picked up just to see how much of a novel I've written so far. I'm curious about what in particular is causing the problem.

Code:

'Sub CountCodeLines()'    Dim VBCodeModule As Object
'    Dim NumLines As Long, N As Long
'    With ActiveWorkbook
'          For N = 1 To .VBProject.VBComponents.Count
'                Set VBCodeModule = .VBProject.VBComponents(N).CodeModule
'                NumLines = NumLines + VBCodeModule.CountOfLines
'          Next
'    End With
'    MsgBox "Total number of lines of code in the project = " & NumLines, , "Code Lines"
'    Set VBCodeModule = Nothing
'End Sub

'original code by johnske  from http://xlvba.fr.yuku.com/topic/112/VBA-code-lines-count-number-of-lines-in-project#.VgHg-dJViko

This is triggering our enterprise virus scan as detecting "X97M/Generic@MM"

The cleaning action nukes the entire module that the code is located on.

I've confirmed that this sole block of code is causing the problem, as I have broken each chunk of code out and put it in their own document and then let the auto-scan do its thing. It only wipes the file that has this chunk in it.

Can anyone help me understand what is causing the scanner to freak out and if there is syntax I can change to avoid this happening in the future?

also asked here:
http://www.mrexcel.com/forum/excel-q...ml#post4288803

return unique values from column B in various sheets

$
0
0
Hello. In sheets 1-10, I want to have all unique values returned into a master tab, without having to go into each tab manually.

[SOLVED] Delete Unwanted Rows

$
0
0
1. What I would like to accomplish is if I have a "Blank Cell in Column A", I would like to Delete that Row.

2. Also If I have "Text in Column A", I would also want to delete that Row. Down to and including Row 144

I have uploaded what my sheet looks like.
I hope this is not asking to much, but I would appreciate it very much to be able to run a marco on this.
Attached Files

Backup to Dropbox

$
0
0
I have a Macro enabled workbook that I would like to have a macro that can be run at the end of the night to back up the file to Dropbox.

This is only for backup incase something goes wrong with the computer or the file.

This is the path C:\Users\JCYC portable\Dropbox[400 Book]

I thought
Code:

ActiveWorkbook.Save (C:\Users\JCYC portable\Dropbox[400 Book])
Error says Expecting line separator.

Need some help.

Printing Visible Data

$
0
0
Hi there,

Not sure if this is possible but anyway.

My spreadsheet extracts information from another spreadsheet (a basic ="Sheet1"!A1 formula with a few other things so it either appears with data or appears blank).

Sometimes the cells will become blank (on purpose). I've set it up (margin size) so the information from each row will appear and print as one page. Sometimes I will information showing on pages 1,2,4,6,7 etc while pages 3,5,8 will appear blank.

Is there a macro or something that can help so when I go to print (Ctrl+P) it only prints the pages that show visible data (even though every cell has a formula, I only want the pages where data is actually appearing, I don't want the pages that return the value to 0/blank printing). In this example only pages 1,2,4,6,7 will print. In excel there is no option to print selected pages, only a range of pages so I don't want to have to keep changing the ranges, I want to be able to hit print and all the pages with data appearing will print and all the blank pages will skip over.

Thanks

Switching Between two open Workbooks

$
0
0
I have a very easy problem that has me scratching my head. In my Workbook VBA code, I browse for another Workbook and open it. I need to copy and paste cells between the main Workbook and Workbook I have browsed for and now have open. The browsed workbook is called ManualImport and I am able to open it in the code below. Now that it is open I need to activate it. I am successful in coping and paste just after the Workbook is open but in the last section of the code below I get an error when I try to switch back to the Workbook that was browsed for. that error occurs after the last comment "------------copies and paste data-----------

I have tried the following:

Workbooks("ManualImport").Activate
Windows("ManualImport").Activate
Windows(ManualImport).Activate

The first is what I have in the VBA code, but all result in errors. What is correct command?

Thanks in advance!

Code:

Sub ManualImport()
'
' ManualImport Macro
'
Dim ManualImport As Variant
'Browse for Manual Import Form

Application.ScreenUpdating = False
Dim efoFile As Workbook
Set efoFile = ActiveWorkbook

fileToOpen = Application.GetOpenFilename _
    (Title:="Please choose the file that you what to import") ', _

    ''
    If fileToOpen = False Then
        MsgBox "No file specified."
        Exit Sub
    Else
       
        [T23] = fileToOpen
        ManualImport = [T23]

    End If
    Application.ScreenUpdating = True


Dim quickImport As Workbook

'----------------Opens Manual Data Entry Form that was browsed for and unprotects the "Data Entry" Tab-------
   
'    Sheets("Cover").Select
    Set quickImport = Workbooks.Open(ManualImport)
    Sheets("Data Entry").Select
    ActiveSheet.Unprotect Password:="protect"
   

   
'------------copies and paste dates-----------
    Range("E16:R16").Select
    Selection.Copy
    Windows("VBA-WorkBook 205.xlsm").Activate
    Sheets("DATA ENTRY").Select
    Range("F12").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
       
'------------copies and paste data-----------
   
    Sheets("Cover").Select
    Workbooks("ManualImport").Activate
    Sheets("Data Entry").Select
    Range("E17:R17").Select
    Selection.Copy
    Windows("VBA-WorkBook 205.xlsm").Activate
    Sheets("DATA ENTRY").Select
    Range("F13").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
       
    End Sub

Loop without DO Error

$
0
0
I'm trying to use a Do While Loop to perform calculations depending on the data entered into one column. The data from the calculation is entered into a second column.

When I try to compile, I get a "Loop without Do" error.

Code:

Sub depth_cal()

gstart = ThisWorkbook.Sheets("Basic Math").Cells(9, 3)
gstop = ThisWorkbook.Sheets("Basic Math").Cells(10, 3)
goda = ThisWorkbook.Sheets("Basic Math").Cells(18, 3)

s1start = ThisWorkbook.Sheets("Basic Math").Cells(9, 6)
s1stop = ThisWorkbook.Sheets("Basic Math").Cells(10, 6)
s1oda = ThisWorkbook.Sheets("Basic Math").Cells(18, 6)

s2start = ThisWorkbook.Sheets("Basic Math").Cells(9, 9)
s2stop = ThisWorkbook.Sheets("Basic Math").Cells(10, 9)
s2oda = ThisWorkbook.Sheets("Basic Math").Cells(18, 9)

s3start = ThisWorkbook.Sheets("Basic Math").Cells(9, 12)
s3stop = ThisWorkbook.Sheets("Basic Math").Cells(10, 12)
s3oda = ThisWorkbook.Sheets("Basic Math").Cells(18, 12)

s4start = ThisWorkbook.Sheets("Basic Math").Cells(9, 15)
s4stop = ThisWorkbook.Sheets("Basic Math").Cells(10, 15)
s4oda = ThisWorkbook.Sheets("Basic Math").Cells(18, 15)

r = 4

Do While Cells(r, 3) <> ""

    If Cells(r, 3) >= gstart And Cells(r, 3) < gstop Then
        Cells(r, 5) = Cells(r, 2) * Cos(goda)
    Else
        If Cells(r, 3) >= s1start And Cells(r, 3) < s1stop Then
            Cells(r, 5) = Cells(r, 2) * Cos(s1oda)
        Else
            If Cells(r, 3) >= s2start And Cells(r, 3) < s2stop Then
                Cells(r, 5) = Cells(r, 2) * Cos(s2oda)
            Else
                If Cells(r, 3) >= s3start And Cells(r, 3) < s3stop Then
                    Cells(r, 5) = Cells(r, 2) * Cos(s3oda)
                Else
                    If Cells(r, 3) >= s4start And Cells(r, 3) < s4stop Then
                        Cells(r, 5) = Cells(r, 2) * Cos(s4oda)
                    Else
                        Cells(r, 5) = "Not Valid"
    End If
   
    r = r + 1
   
Loop
   
End Sub

Any help would be appreciated.

Activate a line-drawing tool

$
0
0
I tend to draw a lot in one of my worksheets, and instead of going Insert ->Shapes -> Line, would be good to have a shortcut tied to a code that activates that function and just gives me a cursor with which I can start drawing. Andy idea how to do this? Basically, the macro has to do the same as if I was to manually go to Insert menu, click on shapes, and select "line" from the long list. I tried to record this, but no luck.

Thanks

Previous Row and next row

$
0
0
Hello,

How can i create a command button to able me to go back to last entered row to be able to modify and update row. After row is corrected i want to be able to go back to access to enter new rows

Can you please help ?

Macro for Find, select row, cut and paste at last row

$
0
0
Hi there

I would like to create a macro for find particular word from the spreadsheet, select the row, cut and Insert cut cells at the last row.

I would like to find text "Customer Deposit" & "Funds Transfer... " on attached test banking file and create macro as above.

Appreciate for your help in advance.

Thanks
Attached Files

Copying and pasting cell links from various workbooks

$
0
0
Hi,

There are 99 folders named CAL1, CAL2, etc until CAL99 . In each of the folders there is workbook named "RESULTS". The full path is as followes:-C:\NEW CALCULATIONS\FIRST\CAL1\RESULTS.xlsx, C:\NEW CALCULATIONS\FIRST\CAL2\RESULTS.xlsx etc.

What i'am looking for is to copy and paste the cell links of the range A3:L14 of C:\NEW CALCULATIONS\FIRST\CAL1\RESULTS.xlsx in another workbook named "EVALUATIONS". The path is as followes- C:\NEW CALCULATIONS\FIRST\EVALUATIONS.xlsx. The range where it should be pasted starts at A2 of sheet2. And after that the ranges from other workbooks to be copied would be A5:L14 consecutively, and should be pasted just below the previous range. In this case the range from second workbook would be pasted at A14 and third workbook at A24 etc. And after finishing the last workbook the evaluations workbook saves and closes itself.

Thank you

Excel Forms/VBA in Apple

$
0
0
I have developed a program in Excel that utilizes VBA, Forms and ActiveX controls that are perfect under WINDOWS OS, but flawed under Apple iOS and Macintosh.

To make it work there, I have to or I assume we can publish the file on remote server where I could share/open and edit the file VIA a remote connection based on WINDOWS OS. For instance, If an Apple user connects to RDC, he/she will able to use the Excel program with Windows functionality.

Is there any alternate to this process. File users will be on both OS, but I need it to function in Apple OS correctly.Please see the attached Wb. Let me know if this could work in Apple OS.

I'm not aware of how this thing will work but I'm sure some expert would def. come up with a solution to this.

Thanks,
AppleTest.xlsm

Consolidate to Master sheet

Viewing all 49926 articles
Browse latest View live