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

[SOLVED] attach contents of textbox in userform as body of email vba

$
0
0
Hi all,
I have seen many threads on line, but could not get a definative solution.
Following code will activate outlook.
I am trying following:
To.... address will be fetched from textbox29
Main body text will be fetched from textbox14

Very challanging.
So far so good this is what I have done.
Please help
Kind regards
:)
Code:

Private Sub CommandButton4_Click()

Dim OutApp As Object
Dim OutMail As Object

Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
.To = Sheets("sheet1").UserForm2.TextBox31.Text
.CC = ""
.BCC = ""
.Subject = "Trying hard "

.Body = Worksheets("sheet1").UserForm2.TextBox14.Text

.Display
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing


End Sub


[SOLVED] NEED HELP! Code that checks all data has been entered before my VBA Macro Runs!

$
0
0
Hi guys,

I have the following macro which allows you to enter a row of data (Only one row will be visible), then you press a command button and the row of data is inputted into another work sheet.

* I would like a way of ensuring that Excel checks the whole row of data has been filled out before allowing itself to run the following macro (which copies and paste all the data across to the other worksheet).

Here is the code I have so far. (Just to advise this macro starts on the "AddRecord" sheet.

Please someone out there if you can help me I would be forever grateful!!! :D

Sub addtoInboundWorkstack()
'
' addtoInboundWorkstack Macro
' Add record to Inbound Workstack
'

'
Range("A3:I3").Select
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 1
Selection.Copy
Sheets("Inbound Workstack").Select
ActiveWindow.ScrollRow = 45
ActiveWindow.ScrollRow = 44
ActiveWindow.ScrollRow = 43
ActiveWindow.ScrollRow = 41
ActiveWindow.ScrollRow = 38
ActiveWindow.ScrollRow = 34
ActiveWindow.ScrollRow = 31
ActiveWindow.ScrollRow = 27
ActiveWindow.ScrollRow = 24
Range("A26").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveCell.Offset(0, 9).Range("A1").Select
Sheets("AddRecord ").Select
ActiveCell.Rows("1:1").EntireRow.Select
Application.CutCopyMode = False
Selection.ClearContents
ActiveCell.Select
End Sub



Happy Easter!

How to code in excel vba the cursor movements based on conditions

$
0
0
Hi to all,

After I did the conditional formatting, I wanted the cursor to skip the colored cells. I used this code:

Private Sub Worksheet_Change(ByVal Target As Range)
'Moves the active cell to the first column when enter button is pressed
If Target.Cells.Count > 1 Then Exit Sub
Select Case Target.Column
Case 12
Cells(Target.Row, Target.Column + 2).Select
Case Else
Exit Sub
End Select


but to no avail it applies to the whole sheet and I did this for "Condominium". How do I make it as a condition when I choose any property type? and then it'll go one step down to column A when the last row is typed/filled in?

For example, if I choose Condominium as my property type, Land Size (i.e. column M) is colored so the cursor will go from column L to Column N. If I choose Land as my property type, Furnished to Floors total (i.e. columns I to L) Bedrooms to Rooms Total (i.e Columns O to Q) Indoor Features to Other Features (i.e. Columns T to W) are colored so the cursor will go from column H to M then Column N to R and then Column S and then move one step below to column A when entered. and so on.

Any ideas or any codes that could help me?

sample sheet.png

Thank you so much!

How to copy data from 1 sheet to another sheet on certain places

$
0
0
Hello,

I'm looking for a VBA solution for the following.

I have an excel 2007 workbook with 3 sheets in it.

Namen groep 1
Database
Groeps overzicht groep 1

On tab Namen groep 1 there are all the names.
On tab Database is a collection of exams with results.
On groeps overzicht groep 1 there i want to have the exam data.

On tab Groeps overzicht groep 1 , i want in column A all the names from Namen groep 1, i can do that but i want each name twice, for instance in cell a11 and in a12 the same name and thats a problem.

In the database tab, you see naam, exam number, results.

Each name wil have 2 exams on one line, so aa-M1T and ab-M1R should be on the same line, aa-M1T in cells E and F, the results from ab-M1R should come in K till S.
For the same name should the next to exams ba-E1T and bb-E1R be on the next line.

Thus anybody has a solution for me.

Yours sincerely

Guido
Attached Files

[SOLVED] apply case's to specific rows

$
0
0
im trying to apply the following case to only the row numbers in the array, any ideas why it wont run past the line "State = Worksheets .. "

Code:

Dim z As Integer
 Dim myArray As Variant
 Dim State As Long
 
 myArray = Array(32, 39, 56, 57, 71, 90, 107, 134) 'define array

 State = Worksheets("PW_TRI").Range("L" & z).Value

 For z = LBound(myArray) To UBound(myArray)

  Select Case State

    Case Is < 249.99

        Worksheets("PW_TRI").Range("X" & z).Value = 0

    Case 250 To 499.99

        Worksheets("PW_TRI").Range("X" & z).Value = Worksheets("PW_TRI").Range("W" & z).Value - 0.75

    Case 500 To 999.99

        Worksheets("PW_TRI").Range("X" & z).Value = Worksheets("PW_TRI").Range("W" & z).Value - 0.5

    Case 1000 To 4999.99

        Worksheets("PW_TRI").Range("X" & z).Value = Worksheets("PW_TRI").Range("W" & z).Value - 0.25

    Case 4999.99 To 10000000

        Worksheets("PW_TRI").Range("X" & z).Value = Worksheets("PW_TRI").Range("W" & z).Value

  End Select


 Next z

clear range of cells unless contains bold type

$
0
0
hi guys

would any of you smarter guys than me know if it is possible to make vba code to clear any cells in range a1:f2500 that do not contain bold type?

thanks in advance

Import Ascii file into excel spread sheet

$
0
0
Hey guys! i am relatively new to using VBA but I have fair experience in C and Matlab. I was wondering whether anyone could help me out. I want to write code so that at the push of a button you can browse and find an ascii file. Select it. and then it will go into the sheet of a excel file that you chose in the code.

Any suggestions or code would be awesome!

Thanks
Glen

NEED HELP! Code that copies row of data to another sheet based on text "Complete"/"Delete"

$
0
0
Hi guys,

In desperate need of some help from you kind strangers.

I need a helping editing my code that MOVES (not copies) a row of data from one work sheet to another depending on what a cell in the STATUS column says.

E.G: Cell in (Column7"Status") = Remove -> I want the row of data to then move to "Delete" sheet.
E.G 2: Cell in (Column7"Status") of Improvement WIP sheet says "Complete" = Move to Workstack -> I want the row of data to then move to "Improvement Workstack" sheet.

I would like to apply this code to each seperate sheet, so then once a job is completed in WIP i can select status as "Complete" and move it to delete, OR if it is to be put on HOLD I can select "Move to Workstack" to move the row to the appropriate sheet.

My workbook:

Sheet 1: Improvement WIP
Sheet 2: Improvement Workstack
Sheet 3: Inbound WIP
Sheet 4: Inbound Workstack
Sheet 5: Delete

Column Names in every sheet:
Col1: Work Item
Col2: Service
Col3: Related Priority
Col4: Owner
Col5: Role
Col6: Objective
Col7: Status
Col8: Target Date

1) I currently have the following code which allows me to perform the action for COMPLETE, however I want the code to also apply the same rule for a status that says "Delete" (Move any row with the status "Remove" to the "Delete" sheet).

2) Currently the code only copies the data but instead I would like it to cut the data.
Current Code:


Code:

Sub SearchForString()

  Dim LSearchRow As Integer
  Dim LCopyToRow As Integer
 
  On Error GoTo Err_Execute
 
  'Start search in row 2
  LSearchRow = 26
 
  While Len(Range("A" & CStr(LSearchRow)).Value) > 0
 
      'If value in column E = "Mail Box", copy entire row to Sheet2
      If Range("G" & CStr(LSearchRow)).Value = "Complete" Then
     
        'Select row in Sheet1 to copy
        Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
        Selection.Copy
       
        'Paste row into Sheet2 in next row
        Sheets("Delete").Select
    Range("A26").Select
    Selection.End(xlDown).Select
    ActiveCell.Offset(1, 0).Range("A1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
       
        'Move counter to next row
        LCopyToRow = LCopyToRow + 1
       
        'Go back to Sheet1 to continue searching
        Sheets("Service Improvement WIP").Select
       
      End If
     
      LSearchRow = LSearchRow + 1
     
  Wend
 
  'Position on cell A3
  Application.CutCopyMode = False
  Range("A3").Select
 
  MsgBox "All matching data has been copied."
 
  Exit Sub
 
Err_Execute:
  MsgBox "An error occurred."
 
End Sub


NEED HELP! Code that copies row of data to another sheet based on text "Complete"/"Delete"

$
0
0
Hi guys,

In desperate need of some help from you kind strangers.

I need a help editing my code that MOVES a row of data from one work sheet to another depending on the value of a cell in the STATUS column.

E.G Sheet = Sheet1

Cell in (Column7"Status") says "Remove "-> I want the row of data to then move to "Delete" sheet.

Another Cell in (Column7"Status") of same sheet says "Complete" = Move to Completed -> I want the row of data to then move to "Completed" sheet.

Another thing that would be great to enter is for a form to open (I will create the form and call it form 1) or message box so that when I change the status it says "Are you sure you want to change the status?", as this of course will move the data to another sheet.

My workbook:

Sheet 1: Improvement WIP
Sheet 2: Improvement Workstack
Sheet 3: Inbound WIP
Sheet 4: Inbound Workstack
Sheet 5: Delete

Column Names in every sheet:
Col1: Work Item
Col2: Service
Col3: Related Priority
Col4: Owner
Col5: Role
Col6: Objective
Col7: Status
Col8: Target Date

What the current code doesn't do:
1) It copies any row that says "Complete" to Complete sheet however I want to ALSO move any row that says "Delete" to the "Delete" sheet.
2) It currently copies data, I would like it to copy the data then delete the row in the original sheet.
3) Doesn't contain messagebox/form as mentioned above.

Code:
Code:

Sub SearchForString()

  Dim LSearchRow As Integer
  Dim LCopyToRow As Integer
 
  On Error GoTo Err_Execute
 
  'Start search in row 2
  LSearchRow = 26
 
  While Len(Range("A" & CStr(LSearchRow)).Value) > 0
 
     
      If Range("G" & CStr(LSearchRow)).Value = "Complete" Then
     
        'Select row in Sheet1 to copy
        Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
        Selection.Copy
       
        'Paste row into Sheet2 in next row
        Sheets("Delete").Select
    Range("A26").Select
    Selection.End(xlDown).Select
    ActiveCell.Offset(1, 0).Range("A1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
       
        'Move counter to next row
        LCopyToRow = LCopyToRow + 1
       
        'Go back to Sheet1 to continue searching
        Sheets("Service Improvement WIP").Select
       
      End If
     
      LSearchRow = LSearchRow + 1
     
  Wend
 
  'Position on cell A3
  Application.CutCopyMode = False
  Range("A3").Select
 
  MsgBox "All matching data has been copied."
 
  Exit Sub
 
Err_Execute:
  MsgBox "An error occurred."
 
End Sub

Hyperlink macro between 2 worksheets

$
0
0
1st cell BD4 (worksheet: SumList) -- hyperlink to cell B17 (Communication_History) -- hyperlink back to A4 (worksheet: SumList)
2nd cell BD5 (worksheet: SumList) -- hyperlink to cell B43 (Communication_History) -- hyperlink back to A5 (worksheet: SumList)
This goes on for 1000 records.

Each time the hyperlink to (Communication_History) is with an increment of 26 cells.
The hyperlink back to (worksheet: SumList) is with an increment of 1 cell.

How do I create a macro to hyperlink for 1000 records.

Thank you.

Import data from password protected php website (semicolon separated data)

Change content of one cell based on content of another

$
0
0
Hello it's been a while since I've had to format a spreadsheet and I am looking for some guidance please.

I have a Formula tab where I have a column with one value (ie. 1800) and the next column showing another value (ie. 2). What I am trying to achieve is to have the '2' appear in 'S14' (which is on worksheet May 7) when I place 1800 in 'D14' on that worksheet.

I really hope this makes sense.

Thank you in advance for your help.

Flora

Userform HTML email format help needed please

$
0
0
Hello all

I have a userform which sends the form entries via email, I have it working fine when sending as Plain text however I want to send in HTML and I'm struggling with the code to enter line breaks etc

This is an extract of the code for the email body which I need to format to work with HTML. Currently it populates the form entries to email however I can't add line breaks as needed

Code:

Body = "OrderIT Reference :" & iOrderIT _
    & vbCrLf & "Customer :" & iCustomer _

Does anyone know how I would write the code so I have OrderIT Reference : iOrderIt, then a line break, with Customer : iCustomer on the next line?

I'm very much a VBA novice so any help would be greatly appreciated

Many thanks in advance

Twaddy

to compare between two workbooks and retrieve data..if match is found

$
0
0
hi Gurus,

im new macros...im stuck with a concept.. dont know how to procees further.



I have a workbook with for ex 30*5 matrix with data. i need to group these data in sheet2 with condition if data in column D occurs greater then or equal to 5. Rest/lesser then can be ignore..
NOTE : with space of two columns left after every grouping.



After grouping, i need to check whether there is a match between column c,d in (sheet2)workbook1 with coulmn a,b in workbook2.

if it matches i need to copy contents from coulmn B,C,D from workbook2 and paste into column E,F,G in sheet2/workbook1.

i have attached a sample workbook...

https://app.box.com/s/1q2kv9mhd8mmiagj0gb7
https://app.box.com/s/8huhjpcwe1xwpe0vwlms

Thanks in advance...

TextBox - Display hours greater than 24 and negative hours too.

$
0
0
First I'll start to tell I'm new in VBA Coding, which mean I don't understand everything you most explain, but I'll try !!

I use Textboxes in a UserForm to display values, when I type a value in another TextBox, using a code in a Module - And it works.

Let me explain.
A normal work week in my country is 37 hours.
If I work in a 2 weeks shift, the normal time will be (2 weeks x 37 hours) = 74 hours.
But maybe I work 76 hours in the first 2 weeks shift and 72 hours in the next 2 weeks shift.

It will show.......74:00 hours
Working time.....76:00 hours
Overtime............2:00 hours

It will show.......74:00 hours
Working time.....72:00 hours
Undertime.........-2:00 hours

The cell in the worksheet show the correct value and the negative value too, using 1904 system in the Excels settings.

What I need is a code, that display more than 24 hours and a negative hours value too, in the Textboxes.
I use Excel 2010 and can't use the code [hh]:mm

When I get the code, I'm not sure where to place it.



This is the TextBox in the UserForm
Code:

Private Sub TextBox87_Change()

    ' Do I place the value code here or in the Module ??

End Sub



And this is the Module, where I had tried different codes, but without luck.
Code:

Sub Turnus_1

    Turnus_Form1.TextBox87.Value = Sheets(5).Range("V8").Value
  'TextBox87.Text = Application.WorksheetFunction.Text(nomib, "hh:mm")
    'TextBox87.Text = Application.WorksheetFunction.Text(maxb, "hh:mm")
    'TextBox87.Text = Application.WorksheetFunction.Text(minb, "hh:mm")


End Sub

Thank you in advance

Ib

Constant for CHR(27)?

$
0
0
Is there any VB constant for CHR(27)?

For example, vbTab is the VB constant for Chr(9).

I thought vbKeyEscape was the equivalent, but it's returning a false when comparing the two.

VBA Sum Values By Row Heading

$
0
0
Hi, I wonder whether someone could help me please.

Using a solution from @AB33 from a post I made here: http://www.excelforum.com/excel-prog...-headings.html, I've been able to put together a script which sums specific figures if a date field matches a column heading.

In a live environment, I've also been able to make some changes to take account of additional filters I want to apply to the data extracted from the 'Source' to the 'Destination' sheets.

I've now come across another hurdle, which I'm afraid my knowledge, or lack of it has led me to making a new post and is the last part of my project. Please note I did post this question here:http://www.ozgrid.com/forum/showthread.php?t=187735 and although I have been fortunate to receive many 'views', I've not been able to find an answer.

What I'm trying to achieve is as follows by adaptation of the original code is as follows:

Rather than totalling the figures from Column E on the "In Flight Projects" (Source) sheet, where the value in Column D matches the column headers on "Output" (Destination) sheet,
I would, if at all possible please, like to total the figures from Column E on the "In Flight Projects" sheet where the value in Column B on the "In Flight Projects" sheet matches the rows in Column B on the "Output" sheet.

I just wondered whether someone could possibly look at this please and offer some guidance on how I may achieve this.

I appreciate that my description may not be the most straight forward, so I have attached a file to hopefully illustrate my issue.
  • The "In Flight Projects" sheet contains the raw data.
  • The "Desired Output" sheet illustrates how I'd like the final results to look, and
  • The "Output" sheet is being used to test the code.

Many thanks and kind regards

Chris
Attached Files

Search A, Manipulate B

$
0
0
NEWBIE question here:

I have two columns, A with an integer value as an identifier and B with a decimal value for each. My A values are not unique. For each value of A, I would like to return the mean of B values and totals of B values.
Thanks

I have attached an example worksheet
Attached Files

AutoFilter Dates

$
0
0
I am have issues getting this to work. It works fine with wors but not dates.

N4:S4 have dates in the. I have the cells formatted as text and I have another macro that gets these dates from another workbook and puts them in N3:S3. I then copy and paste them as values into N4:S4. How can I fix this issue? Thanks for help, Ive been trying to fix for an hour.

HTML Code:

    ActiveSheet.Range("$O$71550:$Y$146550").AutoFilter Field:=2, Criteria1:=Array( _
      Range("N4"), Range("O4"), Range("P4"), Range("Q4"), Range("R4"), Range("S4")), Operator:=xlFilterValues

Macro to Save Excel sheet as comma delimited txt file

$
0
0
Hi,

i am new to macros. can anyone help me in providing a macro to save an excel sheet to comma delimited txt file. Also, My sheet has 1st row as table columns and i dont want to export them in my txt file.

Thanks,
-Dileep
Viewing all 49948 articles
Browse latest View live