Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1460to1464
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Daten durch Knopfdruck in bestimmter Anordnung

Daten durch Knopfdruck in bestimmter Anordnung
06.12.2015 17:22:10
viccci0412

Hallo zusammen,
ich möchte, dass die Daten aus meiner Exceldatei in folgendem Format in einer Textbox ausgegeben werden:
Hamburg=0.3;
Berlin=0.1;
Stuttgart=0.4;
München=0.2
Dadurch habe ich mit VBA eine Schaltfläche installiert, weiß aber nicht was ich in das Makro schreiben soll. Kann mir jemand bitte weiterhelfen?
Grüße
viccci0412
Leider kann ich die Exceldatei nicht hochladen, sie ist aber sehr einfach aufgebaut:
Spalte A die 4 Städte untereinander, Spalte B die Prozentzahlen (z.B. 30%, 10% etc.)

5
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Daten durch Knopfdruck in bestimmter Anordnung
06.12.2015 17:24:53
Sepp
Hallo Vicci,
TextBox wo? In der Tabelle, auf einem UserForm? Wie heißt die Textbox?
Gruß Sepp

AW: Daten durch Knopfdruck in bestimmter Anordnung
06.12.2015 17:37:43
viccci0412
Hallo Sepp,
vielen Dank erstmal für Deine Antwort! Ich möchte den Output entweder direkt im selben Tabellenblatt (in einem anderen Zellbereich) oder auch gerne in einem Pop-Up. An sich bin ich hier flexibel, die Daten sollen nur in diesem Format generiert werden, sodass sie dann per Copy-Paste in eine Datenbank hochgeladen werden können.
Viele Grüße
Vici

Anzeige
AW: Daten durch Knopfdruck in bestimmter Anordnung
06.12.2015 17:53:48
Sepp
Hallo Vici,
folgenden Code in eine allgemeines Modul. Weise die Prozedur "CopyTextToClipboard" einer Schaltfläche zu.
Es erscheint eine Msgbox mit dem Text, der Text befindet sich bereits in der Zwischenablage.
' **********************************************************************
' Modul: Modul1 Typ: Allgemeines Modul
' **********************************************************************

Option Explicit

#If VBA7 Then
Declare PtrSafe Function GlobalUnlock Lib "kernel32" (ByVal hMem As LongPtr) As Long
Declare PtrSafe Function GlobalLock Lib "kernel32" (ByVal hMem As LongPtr) As Long
Declare PtrSafe Function GlobalAlloc Lib "kernel32" (ByVal wFlags As LongPtr, _
  ByVal dwBytes As LongPtr) As Long
Declare PtrSafe Function CloseClipboard Lib "User32" () As Long
Declare PtrSafe Function OpenClipboard Lib "User32" (ByVal hwnd As LongPtr) As Long
Declare PtrSafe Function EmptyClipboard Lib "User32" () As Long
Declare PtrSafe Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, _
  ByVal lpString2 As Any) As Long
Declare PtrSafe Function SetClipboardData Lib "User32" (ByVal wFormat _
  As LongPtr, ByVal hMem As LongPtr) As Long
#Else
Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, _
  ByVal dwBytes As Long) As Long
Declare Function CloseClipboard Lib "User32" () As Long
Declare Function OpenClipboard Lib "User32" (ByVal hwnd As Long) As Long
Declare Function EmptyClipboard Lib "User32" () As Long
Declare Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, _
  ByVal lpString2 As Any) As Long
Declare Function SetClipboardData Lib "User32" (ByVal wFormat _
  As Long, ByVal hMem As Long) As Long
#End If

Public Const GHND = &H42
Public Const CF_TEXT = 1
Public Const MAXSIZE = 4096

Function ClipBoard_SetData(MyString As String)
'PURPOSE: API function to copy text to clipboard
'SOURCE: www.msdn.microsoft.com/en-us/library/office/ff192913.aspx

Dim hGlobalMemory As Long, lpGlobalMemory As Long
Dim hClipMemory As Long, X As Long

'Allocate moveable global memory
hGlobalMemory = GlobalAlloc(GHND, Len(MyString) + 1)

'Lock the block to get a far pointer to this memory.
lpGlobalMemory = GlobalLock(hGlobalMemory)

'Copy the string to this global memory.
lpGlobalMemory = lstrcpy(lpGlobalMemory, MyString)

'Unlock the memory.
If GlobalUnlock(hGlobalMemory) <> 0 Then
  MsgBox "Could not unlock memory location. Copy aborted."
  GoTo OutOfHere2
End If

'Open the Clipboard to copy data to.
If OpenClipboard(0&) = 0 Then
  MsgBox "Could not open the Clipboard. Copy aborted."
  Exit Function
End If

'Clear the Clipboard.
X = EmptyClipboard()

'Copy the data to the Clipboard.
hClipMemory = SetClipboardData(CF_TEXT, hGlobalMemory)

OutOfHere2:
If CloseClipboard() = 0 Then
  MsgBox "Could not close Clipboard."
End If

End Function

Sub CopyTextToClipboard()
Dim rng As Range
Dim strTxt As String

For Each rng In Range("A2:A5")
  strTxt = strTxt & rng.Text & "=" & Replace(rng.Offset(0, 1).Value, ",", ".") & ";" & vbCrLf
Next

strTxt = Left(strTxt, Len(strTxt) - 3)

ClipBoard_SetData strTxt

MsgBox strTxt & vbLf & vbLf & "Der Text steht in der Zwischenablage zur Verfügung!", vbInformation

End Sub

Gruß Sepp

Anzeige
=A1&"="&B1&";"
06.12.2015 18:30:39
Michael
Hi zusammen,
oder, wenn es denn wirklich mit Dezimalpunkt sein soll: =WECHSELN(A1&"="&B1&";";",";".")
Den fehlenden ; in der untersten Zeile könnte man auch behandeln, aber die DB wird kein Problem damit haben.
Schöne Grüße,
Michael

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige